So far I have the following code:
colors = ('k','r','b')
ax = []
for i in range(3):
ax.append(plt.axes())
plt.plot(datamatrix[:,0],datamatrix[:,i],colors[i]+'o')
ax[i].set(autoscale_on=True)
With the autoscale_on=True option for each axis, I thought each plot should have its own y-axis limits, but it appears they all share the same value (even if they share different axes). How do I set them to scale to show the range of each datamatrix[:,i] (just an explicit call to .set_ylim()?) And also, how can I create an offset y-axis for the third variable (datamatrix[:,2]) that might be required above? Thanks all.
It sounds like what you’re wanting is subplots… What you’re doing now doesn’t make much sense (Or I’m very confused by your code snippet, at any rate…).
Try something more like this:
Edit:
If you don’t want subplots, your code snippet makes a lot more sense.
You’re trying to add three axes right on top of each other. Matplotlib is recognizing that there’s already a subplot in that exactly size and location on the figure, and so it’s returning the same axes object each time. In other words, if you look at your list
ax, you’ll see that they’re all the same object.If you really want to do that, you’ll need to reset
fig._seento an empty dict each time you add an axes. You probably don’t really want to do that, however.Instead of putting three independent plots over each other, have a look at using
twinxinstead.E.g.