1

With given DF I would like to save all plots (one month per page) in one pdf file.

Example DataFrame:

%matplotlib inline
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages

index=pd.date_range('2011-1-1 00:00:00', '2011-11-30 23:50:00', freq='15min')
df=pd.DataFrame(np.random.randn(len(index),3).cumsum(axis=0),columns=['A','B','C'],index=index)

df_hour = df.resample("H", how="mean")
df_day = df_hour.resample("D", how="sum")

results_group = df_day.groupby(lambda x: x.month)

I know how to save each plot in one file:

with PdfPages('test.pdf') as pdf:
    for key, group in results_group:
        fig=group.plot().get_figure()
        plt.ylabel('Temp. [$^\circ$C]')
        savefig(fig)

But don't know how to change for example xticklabels, using this code:

for ax, group in results_group:
    ax = group.plot(colormap='prism',kind='bar', stacked=True)
    ax.set_xticklabels(df_day.index.format())

or plot C column at secondary y:

for key, group in results_group:
    ax = group[['A', 'B']].plot()
    group[['C']].plot(secondary_y=True, ax=ax)
Michal
  • 1,927
  • 5
  • 21
  • 27

0 Answers0