我使用下面的代码在同一个图中生成3个图表,但它烦人地打开了3个窗口。我按照链接中给出的步骤操作 http://matplotlib.sourceforge.net/users/recipes.htm。有人请帮帮我。我想在一个窗口中获取所有图表。
import matplotlib.pyplot as plt
time = [1,2,3]
value = {}
value['x'] = [1,2,3]
value['y'] = [1,4,9]
value['z'] = [1,8,27]
for k, dimension in enumerate(['x', 'y', 'z']):
fig, axs = plt.subplots(3, 1, sharex=True,sharey=True)
axs[k].plot(time, value[dimension])
plt.show()
更新:已解决 以下版本工作正常。子图位于for循环内。
import matplotlib.pyplot as plt
time = [1,2,3]
value = {}
value['x'] = [1,2,3]
value['y'] = [1,4,9]
value['z'] = [1,8,27]
fig, axs = plt.subplots(3, 1, sharex=True,sharey=True)
for k, dimension in enumerate(['x', 'y', 'z']):
axs[k].plot(time, value[dimension])
plt.show()