在matplotlib中显示主打印标题和子打印标题

2024-09-28 21:00:28 发布

您现在位置:Python中文网/ 问答频道 /正文

如截图所示,我们看到的只有一个标题-两个子版块中的一个。我缺少有关如何显示以下三个标题的详细信息:

  • 总图
  • 子批次1
  • 子批次2

下面是子片区和标题的相关代码:

    fig = plt.figure()
    fig.suptitle('Power Iteration Clustering Inputs And Outputs') #NO show
    ax = fig.add_subplot(211)
    self.plotInputCircles(ax)
    ax.set_title('Input Circles Data',fontsize='medium')  #Shows up!
    ax = fig.add_subplot(212)
    self.plotOutputs(ax)
    ax.set_title('Output Pseudo Eigenvector',fontsize='medium')  #NO show
    plt.subplots_adjust(hspace=0.1, wspace=0.2)
    plt.show()

enter image description here

更新子程序正在破坏标题显示(如@cel怀疑的那样)。根据@cel的建议,我发布了一个答案,说明了这一点。在


Tags: noselfadd标题titleshowfigplt
1条回答
网友
1楼 · 发布于 2024-09-28 21:00:28

这个问题与头衔无关。根据@cel的提示,我更仔细地研究了生成子批的两个子程序。其中一个有个鬼鬼祟祟的列表理解错误。在

对于读者来说,这里是使用一个可以正常工作的伪sin/cos来更新信息,而不是使用子程序。在

fig = plt.figure()
fig.suptitle('Power Iteration Clustering Inputs And Outputs')
ax = fig.add_subplot(211)
x = np.linspace(-2.5,2.5,100)
ax.plot(x, np.sin(x))
# self.plotInputCircles(ax)
ax.set_title('Labeled Input Circles Data',fontsize='medium')
ax = fig.add_subplot(212)
# self.plotOutputs(ax)
x = np.linspace(-2.5,2.5,100)
ax.plot(x, np.cos(x))
ax.set_title('Output Pseudo Eigenvector',fontsize='medium')
plt.subplots_adjust(hspace=0.5, wspace=1.0)
plt.show()

enter image description here

相关问题 更多 >