Matplotlib add subtitle to figure

11,163

The error is correct, the pyplot library has no .subtitle function, only a .suptitle function.

So you should fix this with:

import matplotlib.pyplot as plt 

plt.figure(figsize = (15, 80))
for i, audio, rate, name in zip(range(len(audios)), audios, rates, names):
    plt.subplot(len(audios), 1, i+1)
    plt.plot(rate, audio)
    plt.xlabel('Time (s)')
    plt.ylabel('Amplitude')
    plt.title(name)
plt.suptitle('Figure 1: Plot amplitude of signal')
plt.show()
Share:
11,163

Related videos on Youtube

Kathryn Schutte
Author by

Kathryn Schutte

Updated on June 04, 2022

Comments

  • Kathryn Schutte
    Kathryn Schutte almost 2 years

    I want to add a title to my figure that contains several subplots.

    Here is my code:

        import matplotlib.pyplot as plt 
    
        plt.figure(figsize = (15, 80))
        for i, audio, rate, name in zip(range(len(audios)), audios, rates, names):
            plt.subplot(len(audios), 1, i+1)
            plt.plot(rate, audio)
            plt.xlabel('Time (s)')
            plt.ylabel('Amplitude')
            plt.title(name)
        plt.subtitle('Figure 1: Plot amplitude of signal')
        plt.show()
    

    The error I get is : module 'matplotlib.pyplot' has no attribute 'subtitle' I can't figure out why this doesn't work since it is written that way in the matplotlib documentation ! Thank you for your help.

    • Willem Van Onsem
      Willem Van Onsem over 5 years
      It is .suptitle, not .subtitle.
  • Sheldore
    Sheldore over 5 years
    Should have been posted as a comment given your golden badge and that it was a typo error but anyway
  • Willem Van Onsem
    Willem Van Onsem over 5 years
    @Bazingaa: I'm not really sure it was a typo in the "strict" sense. After all .subtitle would be a valid candidate. So I think it was not a "typing mistake". It is more a classical "misread" and then use it that way.