[英]Drawing small-multiple charts with matplotlib - how to set figure size?
我正在用matplotlib绘制小倍数。 这是我的代码:
import matplotlib.pyplot as plt
f, axarr = plt.subplots(4, 4)
for name in ccgs:
x = np.array([k for k in ccgs[name]['dates']])
y = np.array([v for v in ccgs[name]['values']])
axarr[i / 4, i % 4].plot(x, y)
plt.show()
当输出为4x4网格时,此方法非常有效,但是当我开始添加更多子图时,效果非常差。
看起来像这样-仅前16个图表具有数据这一事实是无关紧要的,这是我所关注的压缩性:
我如何拉伸matplotlib生成的图形,以便每个图表都是合理的高度?
我以为可以简单地设置图形的总像素高度,但是与Google的距离不是很远。
我不在乎matplotlib生成的交互式输出是否不是很有用,只要我可以生成最终的.png
文件即可。
fig, ax_lst = plt.subplots(15, 10, figsize=(15, 10))
for ax in ax_lst.ravel():
ax.xaxis.get_major_locator().set_params(nbins=3)
ax.yaxis.get_major_locator().set_params(nbins=2)
fig.tight_layout(pad=0, h_pad=.1, w_pad=.1)
要么
fig, ax_lst = plt.subplots(15, 10, figsize=(15, 10), sharex='col', sharey='row')
for ax in ax_lst.ravel():
ax.xaxis.get_major_locator().set_params(nbins=3)
ax.yaxis.get_major_locator().set_params(nbins=2)
fig.tight_layout(pad=0, h_pad=.1, w_pad=.1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.