[英]How to align subplot with specified size?
我有很多不同的图,必须严格指定尺寸。 每个文件一个绘图。 问题是,当尺寸太大时,我在左边的子图中有一些空闲空间,我想裁剪这些空间。 我不能使用subplots_adjust
因为小尺寸的地块也将被croped。 当我调用savefig
时,我也不能使用tight
选项。 那么,如何将我的所有图与所有文件中的固定缩进对齐到左侧?
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)
我认为你可以使用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)
你也可以使用类似的东西
fig.subplots_adjust(right=0.9, left=0.1, top=0.9, bottom=0.1, wspace=0.2)
而不是plt.tight_layout()
。 如果你想。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.