我的目标是创建许多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
)
我知道如何将图形设置为正方形,我需要的是将输出图像设置为正方形。从概念上讲,这与获取默认输出图像,然后根据需要扩展其背景以使图像成为正方形一样简单。
发布于 2016-01-28 09:43:06
不知道这是否是你想要的,但它为我生成了一个600x600像素的png图像。
import numpy as np
import matplotlib.pyplot as plt
a = np.random.normal(size=1000)
b = np.random.normal(size=1000)
fig = plt.figure(figsize=(6,6))
plt.plot(a,b,'g.')
plt.xlabel("x axis label")
plt.ylabel("y axis label")
plt.title("Random numbers in a scatter plot")
fig.savefig("test.png")
https://stackoverflow.com/questions/34977746
复制相似问题