【发布时间】:2018-08-17 14:53:00
【问题描述】:
目前,我制作了一个子图(使用matplotlib)
import matplotlib.pyplot as plt
fig, (ax1, ax2, ax3) = plt.subplots(3, sharex=True)
我想要一个可变数量 (n) 的子图,命名为 ax1, ax2, ... axn 所以应该是这样的
mylist = []
for num in xrange(n):
mylist.append('ax'+str(num))
fig, (mylist) = plt.subplots(n, sharex=True)
但是,这不起作用,因为它只是覆盖“mylist”而不是使用列表中的名称。
另一种解决方案是,如果我没有创建列表而只使用它为轴创建的名称,但是,我不知道如何访问这些名称。 如果我尝试使用
访问名称mylist[0]
控制台说
<matplotlib.axes._subplots.AxesSubplot object at 0x09BFAEF0>
我如何使用这个数字来绘制一条线,例如
ax1.plot(data[:,0], data[:,1]
【问题讨论】:
标签: python loops matplotlib pythonxy