Plotting two axes in gnuplot
Asked Answered
P

2

39

Is it possible to plot two curves, with two corresponding axes in gnuplot, each of which has a different scale?

For example, y=x**2 and y=x**4 in the same graph (they vary enough to be "uncomfortable" when plotted with the same scale).

Predetermine answered 13/5, 2010 at 14:39 Comment(4)
@Kazark - Would you mind explaining what was the point of that edit? To make the question non-compatible with both answers, or?Predetermine
@Idigas There was of course no intention of obscuring the question. If you think I have done so, you can of course roll back the edit.Phyte
@Kazark - So why the edit then?Predetermine
Why not to accept one of answers?Laws
B
57

You can have the axes handled automatically without you having to scale them yourself and keep auto-scaling:

set terminal jpeg
set output 'graph.jpg'

set xrange [-10:10]
set ytics 10 nomirror tc lt 1
set ylabel '2*x' tc lt 1
set y2tics 20 nomirror tc lt 2
set y2label '4*x' tc lt 2
plot 2*x linetype 1, 4*x linetype 2 axes x1y2

output of the script

Beatup answered 22/5, 2012 at 18:24 Comment(1)
As my axes naturally have a different scale, I found autofreq useful. e.g. set ytics autofreq tc lt 1Austronesia
T
15

It is possible to set different ranges for y and y2 (the right axes), and even to set the color of the labels/tics independently.

Then we simply divide the second function by 2 (or something appropriate) and set the colors... as in this example:

set xrange [-10:10]
set yrange [-20:20]
set y2range [-40:40]

set ytics 10 nomirror tc lt 1
set ylabel '2*x' tc lt 1

set y2tics 20 nomirror tc lt 2
set y2label '4*x' tc lt 2

plot 2*x linetype 1, 4*x/2+.5 linetype 2
Trilingual answered 14/5, 2010 at 15:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.