2016-11-22 130 views

回答

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

下面是對沒有留下任何空間和大量的右側與facecolor設置爲紅色,一個誇張的例子,所以我們可以清楚地看到:

fig.subplots_adjust(left=left, bottom=bottom, right=right, top=top, 
      wspace=wspace, hspace=hspace) 
plt.savefig('image.png', facecolor='red') 

enter image description here