Reputation: 95
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
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