【发布时间】:2016-11-22 00:34:42
【问题描述】:
绘制数据框时:
d_f.plot()
plt.savefig(image.png, bbox_inches='tight')
bbox_inches='tight' 可用于彻底删除最终 .png 图像中的大量框架(空白)。
是否可以只减少一点帧?
【问题讨论】:
标签: python python-2.7 python-3.x pandas matplotlib
绘制数据框时:
d_f.plot()
plt.savefig(image.png, bbox_inches='tight')
bbox_inches='tight' 可用于彻底删除最终 .png 图像中的大量框架(空白)。
是否可以只减少一点帧?
【问题讨论】:
标签: python python-2.7 python-3.x pandas matplotlib
bbox_inches='tight' 或 plt.tight_layout 都是自动的。
您应该改用plt.subplots_adjust():
ax = df[['y','w']].plot()
fig = ax.get_figure()
left = 0.125 # the left side of the subplots of the figure
right = 0.9 # the right side of the subplots of the figure
bottom = 0.1 # the bottom of the subplots of the figure
top = 0.9 # the top of the subplots of the figure
wspace = 0.2 # the amount of width reserved for blank space between subplots
hspace = 0.2 # the amount of height reserved for white space between subplots
# These two can be called on 'fig' instead of 'plt' too
plt.subplots_adjust(left=left, bottom=bottom, right=right, top=top,
wspace=wspace, hspace=hspace)
plt.savefig('image.png')
如果你想左边没有空格,设置left=0,如果你不想右边没有空格,设置right=1。
这是一个夸张的例子,左边没有空格,右边很多,facecolor设置为红色,所以我们可以清楚地看到:
fig.subplots_adjust(left=left, bottom=bottom, right=right, top=top,
wspace=wspace, hspace=hspace)
plt.savefig('image.png', facecolor='red')
【讨论】: