matplotlib - overlaying plots.

Ant antroy at gmail.com
Thu May 14 07:41:27 EDT 2009


Hi All,

I am trying to get matplotlib to overlay a couple of graphs, but am
getting nowhere. I originally thought that the following may work:

>>> x = [1,2,3,4,5]
>>> y = [2,4,6,8,10]
>>> y2 = [1,4,9,16,25]

>>> plot(x, y)
>>> plot(x, y2)

Now this works as desired, however, the actual case I have is more
like this:

>>> x = [1,2,3,4,5]
>>> y = [2,4,6,8,10]
>>> y2 = [.0001, .0002, .0003, .0004, .0005]

Now the graph is useless, since the results are plotted on the same
axis. What I really want is two different sets of axes, each scaled
appropriately, but overlayed.

The data I actually have, is one set of axes plotting distance against
elevation, and a second plotting distance against speed. The former
has (y-coord) units in the range 0-2000 ft and the latter 0 - 0.01
miles/second. I want them on the same graph, so points can be easily
correlated, but overlayed so that each line has a different scale on
the y-axis. The closest I can get is to have two subplots, one above
the other.

Thanks in advance,

Ant.




More information about the Python-list mailing list