Currently, I make a subplot (using matplotlib
) with
import matplotlib.pyplot as plt
fig, (ax1, ax2, ax3) = plt.subplots(3, sharex=True)
I want a variable number (n) of subplots in my plot named ax1, ax2, ... axn So it should be something like
mylist = []
for num in xrange(n):
mylist.append('ax'+str(num))
fig, (mylist) = plt.subplots(n, sharex=True)
However, this doesn't work because it just writes over "mylist" instead of using the names in the list.
Another solution would be if I didn't create the list and just used the names it creates for the axes, however, I do not know how to access these names. If I try to access the names with
mylist[0]
The console says
<matplotlib.axes._subplots.AxesSubplot object at 0x09BFAEF0>
How can I use this number to plot with a line such as
ax1.plot(data[:,0], data[:,1]