绘制数据框时:
d_f.plot()
plt.savefig(image.png, bbox_inches='tight')
bbox_inches='tight'
可用于彻底删除最终.png图像中的大量帧(空白区域)。
是否可以减少一点帧?
答案 0 :(得分:0)
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
。
这是一个夸张的例子,左边没有空格,右边有很多面部颜色设置为红色,所以我们可以清楚地看到:
fig.subplots_adjust(left=left, bottom=bottom, right=right, top=top,
wspace=wspace, hspace=hspace)
plt.savefig('image.png', facecolor='red')