[英]How to align subplot with specified size?
I have a lot of different plots, wich sizes must be strongly specified.我有很多不同的图,必须严格指定尺寸。 One plot per one file.
每个文件一个绘图。 The problem is that when size too large I have some free spaces in subplot from the left, which I want to crop.
问题是,当尺寸太大时,我在左边的子图中有一些空闲空间,我想裁剪这些空间。 I can't use
subplots_adjust
because plots with small sizes will be croped too.我不能使用
subplots_adjust
因为小尺寸的地块也将被croped。 Also I can't use tight
option when I call savefig
.当我调用
savefig
时,我也不能使用tight
选项。 So, how can I align all my plots to the left side with fixed indent in all my files?那么,如何将我的所有图与所有文件中的固定缩进对齐到左侧?
import sys, os
import matplotlib.pyplot as plt
path = sys.path[0]
sizes = [(12,3,), (4,3,)]
x = range(20)
for i, size in enumerate(sizes):
fig = plt.figure(figsize = size, dpi = 80, facecolor='white', edgecolor=None, linewidth=0.0, frameon=True, subplotpars=None)
ax = fig.add_subplot(111)
ax.plot(x)
plt.ylabel ('Some label')
fig.savefig(os.path.join(path, 'size_'+str(i)+'.png'), dpi=80, facecolor=fig.get_facecolor(), edgecolor=None, papertype=None, format='png' ,transparent=False)
I think you can just use tight_layout() :我认为你可以使用tiny_layout() :
import sys, os
import matplotlib.pyplot as plt
path = sys.path[0]
sizes = [(12,3,), (4,3,)]
x = range(20)
for i, size in enumerate(sizes):
fig = plt.figure(figsize = size, dpi = 80, facecolor='white', edgecolor=None,linewidth=0.0, frameon=True, subplotpars=None)
ax = fig.add_subplot(111)
ax.plot(x)
plt.ylabel ('Some label')
plt.tight_layout()
fig.savefig(os.path.join(path, 'size_'+str(i)+'.png'), dpi=80,facecolor=fig.get_facecolor(), edgecolor=None, papertype=None, format='png',transparent=False)
Also you can use something like你也可以使用类似的东西
fig.subplots_adjust(right=0.9, left=0.1, top=0.9, bottom=0.1, wspace=0.2)
instead of plt.tight_layout()
.而不是
plt.tight_layout()
。 If you want.如果你想。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.