matplotlib 为什么图表中不打印标题和x标签?

5ssjco0h  于 2023-03-03  发布在  其他
关注(0)|答案(3)|浏览(168)

此代码生成一个图,但不显示标题和x标签。

normalDistribution = np.random.normal(loc = 0.0, scale = 1.0, size = totalPoints)
rows = 4
columns = 5
fig = plt.figure(figsize =(24, 24))
plt.subplots_adjust(wspace=0.3, hspace=0.4) # to adjust the spacing between subplots
plt.subplot(rows, columns,1)
plt.title = "Normal Dist"
plt.xlabel = "Sequence #"
plt.scatter(range(0, len(normalDistribution)), normalDistribution, c='green')

vxbzzdmp

vxbzzdmp1#

在代码末尾添加plt.tight_layout()
http://omz-software.com/pythonista/matplotlib/users/tight_layout_guide.html

normalDistribution = np.random.normal(loc = 0.0, scale = 1.0, size = totalPoints)
rows = 4
columns = 5
fig = plt.figure(figsize =(24, 24))
plt.subplots_adjust(wspace=0.3, hspace=0.4) # to adjust the spacing between subplots
plt.subplot(rows, columns,1)
plt.title = "Normal Dist"
plt.xlabel = "Sequence #"
plt.scatter(range(0, len(normalDistribution)), normalDistribution, c='green')

plt.tight_layout()
m0rkklqb

m0rkklqb2#

您可以保存图形,例如:

fig = plt.figure()
fig.suptitle('insert a title', fontsize=20)
plt.xlabel('xlabel', fontsize=18)
plt.ylabel('ylabel', fontsize=16)
fig.savefig('test.jpg')

我不知道这是否可能,打印数字。

m2xkgtsf

m2xkgtsf3#

使用plt.title()plt.xlabel()方法

plt.title =plt.xlabel =将覆盖您要使用的函数。

normalDistribution = np.random.normal(loc = 0.0, scale = 1.0, size = 1000)
rows = 4
columns = 5
fig = plt.figure(figsize =(24, 24))
plt.subplots_adjust(wspace=0.3, hspace=0.4) # to adjust the spacing between subplots
plt.subplot(rows, columns,1)

plt.title("Normal Dist")
plt.xlabel("Sequence #")

plt.scatter(range(0, len(normalDistribution)), normalDistribution, c='green')

相关问题