Matplotlib 给图添加副标题
Matplotlib add subtitle to figure
我想为包含多个子图的图形添加标题。
这是我的代码:
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()
我得到的错误是:module 'matplotlib.pyplot' has no attribute 'subtitle'
我不明白为什么这不起作用,因为它在 matplotlib 文档中是这样写的!感谢您的帮助。
错误正确,pyplot
库有no.su<b>b</b>title
函数,只有一个.su<b>p</b>title
function.
所以你应该解决这个问题:
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.<b>suptitle</b>('Figure 1: Plot amplitude of signal')
plt.show()
我想为包含多个子图的图形添加标题。
这是我的代码:
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()
我得到的错误是:module 'matplotlib.pyplot' has no attribute 'subtitle'
我不明白为什么这不起作用,因为它在 matplotlib 文档中是这样写的!感谢您的帮助。
错误正确,pyplot
库有no.su<b>b</b>title
函数,只有一个.su<b>p</b>title
function.
所以你应该解决这个问题:
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.<b>suptitle</b>('Figure 1: Plot amplitude of signal')
plt.show()