Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 529
Kathryn Schutte Avatar asked Jul 23 '26 09:07

Kathryn Schutte


1 Answers

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()
like image 150
Willem Van Onsem Avatar answered Jul 24 '26 22:07

Willem Van Onsem



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!