我的目标是创建一系列的matplotlib图表,然后将它们排列在一个大数组中。为此,我需要确保matplotlib图表的输出图像是方形的。如何实现呢?
这是我的代码片段:
我知道如何将图形设置为正方形,我需要的是将输出图像设置为正方形。这在概念上就像是取默认输出图像,然后根据需要扩展其背景以使图像成为正方形。
这是我的代码片段:
figure = matplotlib.pyplot.figure()
figure.suptitle(label, fontsize = 20)
#figure.set_size_inches(19.7, 19.7)
matplotlib.pyplot.scatter(
variable_1_values,
variable_2_values,
s = marker_size,
c = "#000000",
edgecolors = "none",
label = label,
)
matplotlib.pyplot.xlabel(label_x)
matplotlib.pyplot.ylabel(label_y)
legend = matplotlib.pyplot.legend(
loc = "center left",
bbox_to_anchor = (1, 0.5),
fontsize = 10
)
print("save {filename}".format(filename = filename))
matplotlib.pyplot.savefig(
filename,
bbox_extra_artists = (legend,),
bbox_inches = "tight",
dpi = 700
)
我知道如何将图形设置为正方形,我需要的是将输出图像设置为正方形。这在概念上就像是取默认输出图像,然后根据需要扩展其背景以使图像成为正方形。
bbox_inches='tight'
,该选项会将保存的图形缩小到图形中艺术家的边界框。 - tacaswellfigure.tight_layout()
(重新排列/调整轴) - tacaswell