我想创建一个绘制多行图和最后一行多列图的函数。
fig = plt.figure()
ax = plt.subplot(3,1,1)
ax.plot(self.dfile['test'], label='test', marker='o', markersize=1, linestyle="", zorder=1)
ax.set_ylabel('test')
ax1 = plt.subplot(3,1,2)
qt = self.do_something(self.dfile['foo'])
ax1.plot(qt, label='foo', marker='x', markersize=1, linestyle="", zorder=1)
ax1.hlines(y=1,xmin=0, xmax=len(qt),color='r', zorder=2, alpha=0.55, linewidth=0.8)
ax1.set_ylabel('foobar')
ax1.set_xlabel('Time (s)')
ax2 = plt.subplot(3,1,3)
x = self.dfile['foo'].value_counts().reset_index()
x1 = self.dfile['foo'][0:150].value_counts().reset_index()
x2 = self.dfile['foo'][150:300].value_counts().reset_index()
x3 = self.dfile['foo'][300:450].value_counts().reset_index()
x4 = self.dfile['foo'][450:600].value_counts().reset_index()
ax2.scatter(x1['index'], x1['foo'], s=2)
ax2.set_yticks([0, 10, 20, 30, 40])
ax2.set_ylabel('Count')
ax2.set_xlabel('some x label')
#ax2.grid(linestyle='-', which='both')
ax3 = plt.subplot(3,2,3)
ax3.scatter(x2['index'], x2['foo'], s=2)
ax3.set_yticks([0, 10, 20, 30, 40])
ax3.set_ylabel('Count')
ax3.set_xlabel('some x label')
fig.tight_layout()
plt.subplots_adjust(wspace=0, hspace=0.15)
file_name = 'test.png'
fig.savefig(OUTPUT_PATH + str(file_name), bbox_inches='tight', dpi=DPI, pad_inches=0.1)
fig.clf()
plt.close()
这是我的尝试。我要确保最后一行的图多列。 这是一个例子