matplotlib - overlaying plots.

A

Ant

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.
 
H

Hyuga

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.

Just scale up the y-axis values of your second graph 200,000 times,
and specify in label that the y-axis for the second graph is velocity
scaled up 200000x for comparison purposes. Nothing wrong with that--
it's done all the time.

On the other hand, I just took a peek at the matplotlib example
gallery, which is very diverse, and it has an example that I think is
exactly what you're looking for: http://matplotlib.sourceforge.net/examples/api/two_scales.html
 
N

norseman

Ant said:
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.

======================
Use scalers to 'sync' the axis (x or y or both on the page)
The 'scales' along the axis need to match or you get your problem.

You know - like trying to do 1:1 but one is meters and the other feet.
That case needs two different graphs (or CAD drawings) each with its own
legend. The scales are not the same. ie... 100meters is not 100feet
By scalling to same units/distance on graph you get overlay ability.

my first thought on your 0-2000ft and miles/sec is to convert miles to
feet and multiply time by enough to be integer values and see if you get
a better visual

one graph means one set of units per axis
or
plot each and scale one to the other
(in CAD it's a case of meters/3.280833333_ to reduce to feet units
.3048 * meters if using International scaler
meters/3.280833333333(infinitely repeating 3s) is US Standard.
The difference cost us a mars rover.
You don't seem to be metric vs US but you do have miss matched units.
miles vs feet, time vs (feet)elevation
or whatever the units distance/elevation may be.
)
target_size / 2nd_graph unit => scaler for that axis (mostly)
since the units are not completely the same type you may need
to experiment.
same units would be time time hours days seconds
linear linear meter feet mile
angular angular mils degrees rads
and so forth.

HTH


Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top