鉴于DF
我想将所有图(每页一个月)保存在一个 pdf 文件中。
示例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)
我知道如何将每个图保存在一个文件中:
with PdfPages('test.pdf') as pdf:
for key, group in results_group:
fig=group.plot().get_figure()
plt.ylabel('Temp. [$^\circ$C]')
savefig(fig)
但不知道如何更改例如 xticklabels,使用以下代码:
for ax, group in results_group:
ax = group.plot(colormap='prism',kind='bar', stacked=True)
ax.set_xticklabels(df_day.index.format())
C column
或在中学 y 处绘图:
for key, group in results_group:
ax = group[['A', 'B']].plot()
group[['C']].plot(secondary_y=True, ax=ax)