Kathryn Schutte
Kathryn Schutte

Reputation: 95

Matplotlib add subtitle to figure

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.

Upvotes: 7

Views: 19829

Answers (1)

willeM_ Van Onsem
willeM_ Van Onsem

Reputation: 476557

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()

Upvotes: 12

Related Questions