WestCoastProjects
WestCoastProjects

Reputation: 63062

Displaying Main and Subplot Titles in matplotlib

As shown in the screenshot we are seeing only one title - for one of the two subplots. I am missing some detail on how to display the following three titles:

Here is relevant code for subplots and titles:

    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

UPDATE the subroutines are corrupting the title displays (as suspected by @cel) . Per suggesion of @cel I am posting an answer stating as much.

Upvotes: 2

Views: 7735

Answers (1)

WestCoastProjects
WestCoastProjects

Reputation: 63062

The problem had nothing to do with titles. Per hint by @cel I looked more closely at the two subroutines that generate the subplots. One of them had a sneaky list comprehension bug.

For readers here is updated info using a dummy sin/cos that works fine instead of the subroutines.

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

Upvotes: 4

Related Questions