嗨,我正在使用matplotlib从不同的csv文件创建多个图。我能够将图创建为另存为单独jpeg的单独图形。我想将所有图形合并在一页和一个文件中。我写的代码如下
path='xxxxx'
for filename in os.listdir(path):
if fnmatch.fnmatch(filename,'*.csv'):
print(filename)
dataframe= pd.read_csv(filename)
dataframe["A"] = pd.to_datetime(dataframe["xxxxx"].astype('object'), errors='coerce').iloc[1:1441]
ax=dataframe.plot(x="A", y="BBBBB", figsize=(60,20), kind='area',fontsize=60,legend=False)
ax.xaxis.set_major_formatter(DateFormatter("%Y-%m-%d %I:%M %p"))
ax.set_ylabel("Number of Steps", fontsize=60, fontweight='bold')
ax.set_ylim(top=80)
ax.set_xlabel("Time", fontsize=60, fontweight='bold')
ax.set_title('Graph for case_{}:'.format(filename), fontsize=60, fontweight='bold')
ax.grid(True)
ax.xaxis.set_ticks_position('bottom')
plt.tight_layout()
plt.savefig('{}_.jpeg'.format(filename), dpi = 300)