Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Multiple Y axes per plot

681 views
Skip to first unread message

JOHN ROBERT LABENSKI

unread,
May 12, 1999, 3:00:00 AM5/12/99
to
Dear Gnuplot people,

After reviewing the manual and experimenting with some of the
availible commands I've been unable to produce a single plot with multiple
y-axes (literally complete axes) and a single x-axis.
For example

reset
set xrange [0:10]
set multiplot
set origin 0,0 #units of screen coordinates
set size 1,1 #screen coordinates
set offsets .8,0,0,0 #units of x-axis, match origin below?
plot sin(x)

set origin .1,0 # lets say I force this to be so
set size .88,1 # Match left hand side?
set offsets 0,0,0,0
plot x
set nomultiscale

This *almost* works, but there seems to be a problem with the
definitions of distance on the plot. Is it possible to calculate the offset
needed for the first graph to start at the y-axis of the second graph? How do
I know what distance is used by the y-axis label? Now, to get the y-axes on
the right hand side to line up. Again I need to find a size in the screen
coordinates that depends on the graph's x-axis that depends on the distance to
the edge of the page?
Am I missing something? If not, please put in my vote for this in the next
version! Thanks for your time.

A disgruntled Gnuplot fan
-John Labenski
jr...@lehigh.edu


Theo Hopman

unread,
May 13, 1999, 3:00:00 AM5/13/99
to
: After reviewing the manual and experimenting with some of the

: availible commands I've been unable to produce a single plot with multiple
: y-axes (literally complete axes) and a single x-axis.

I'm not quite sure what you want -- multiple (vertically stacked,
presumably) plots with similar x-axes, or a single plot with y and y2
axes.

: For example

: reset
: set xrange [0:10]
: set multiplot
: set origin 0,0 #units of screen coordinates
: set size 1,1 #screen coordinates
: set offsets .8,0,0,0 #units of x-axis, match origin below?
: plot sin(x)

: set origin .1,0 # lets say I force this to be so
: set size .88,1 # Match left hand side?
: set offsets 0,0,0,0
: plot x
: set nomultiscale

OK, I tried this, and it looks like you're trying to plot two different
functions with different y-scales on the same plot area. Note that
multiplot is not really intended for this. You can do it, but it doesn't
really work that well, as you're finding out.

: This *almost* works, but there seems to be a problem with the


: definitions of distance on the plot. Is it possible to calculate the offset
: needed for the first graph to start at the y-axis of the second graph? How do
: I know what distance is used by the y-axis label? Now, to get the y-axes on
: the right hand side to line up. Again I need to find a size in the screen
: coordinates that depends on the graph's x-axis that depends on the distance to
: the edge of the page?
: Am I missing something? If not, please put in my vote for this in the next
: version! Thanks for your time.

I would suggest that you use the y2 axis for your second plot as follows:

plot sin(x), x axes x1y2

If you must have both y axes at the left, things get a little trickier,
since you will have to do a lot of fiddling, and your plot will have to
be changed every time you change your data. What you have above will work
if you turn off automatic margin calculation. By setting rmargin and
lmargin to 0, we force a correspondence between screen and plot x
coordinates. Margins are calculated in character widths and heights, and
I think these change depending on the terminal -- I've never been able to
figure out how they work for adjusting the plot size with non-zero values.

reset
set rmargin 0
set lmargin 0
set xrange [0:10]

set multiplot
set origin 0,0

set size 1,1
set offset 1,0,0,0
plot sin(x)

set origin 0.09090909,0
set size 0.90909,1
set offset 0,0,0,0
plot x
set nomultiplot


Note that this is not entirely satisfactory: on some terminals, the y
labels will be left out for the sine curve. This is the case on the X11
terminal, but not on the postscript terminal. The functions both have the
same linetype, so they will have to be manually changed. The keys are
overlaid, so one or both will have to be moved. The outer border
goes through the y labels for the inner plot. Finally, the x axis
labels are printed twice, so if the something isn't quite perfect in the
calculation of offsets, origins and sizes, the labels will be visibly
offset from each other.

THeo


0 new messages