help-octave
[Top][All Lists]

## Re: plot with different axes scale

 From: Paul Kienzle Subject: Re: plot with different axes scale Date: Wed, 7 Aug 2002 11:01:05 -0400

```The following works:

t=linspace(1,10,100)';
plot(t,sin(t))
hold on;
gset y2tics;
y2 = [t,100*cos(t)];
gplot y2 axes x1y2

It would be nice to be able to control this without resorting
to raw gnuplot.  E.g.,
t=linspace(1,10,100)';
plot(t,sin(t))
hold on;
axis x1y2
plot(t,100*cos(t))
hold off
axis x1y1

or even better, specify it in the format string:

t=linspace(1,10,100);
plot(t,sin(t),t,100*cos(t),'Y')

The following patch to __pltopt1__.m and plot.m in your
/usr/share/octave/.../plot directory provides the latter.
Unfortunately, you still have to turn on tic labels before
plotting with:

gset y2tics

and turn them off after plotting with:

gset noy2tics

Paul Kienzle

Index: plot.m
===================================================================
RCS file: /cvs/octave/scripts/plot/plot.m,v
retrieving revision 1.22
diff -c -r1.22 plot.m
*** plot.m      2000/09/08 06:27:45     1.22
--- plot.m      2002/08/07 14:58:05
***************
*** 126,131 ****
--- 126,137 ----
## @item ";title;"
## Here @code{"title"} is the label for the key.
##
+ ## @item X
+ ## @item Y
+ ## Use alternate x/y axis.  Note that you will have to turn on tic labels
+ ## for the alternate axis before plotting with @code{"set y2tics"} and
+ ## turn them off afterward with @code{"set noy2tics"}.
+ ##
## @item +
## @itemx *
## @itemx o
Index: __pltopt1__.m
===================================================================
RCS file: /cvs/octave/scripts/plot/__pltopt1__.m,v
retrieving revision 1.9
diff -c -r1.9 __pltopt1__.m
*** __pltopt1__.m       2000/09/08 06:27:44     1.9
--- __pltopt1__.m       2002/08/07 14:58:05
***************
*** 41,46 ****
--- 41,49 ----
set_xerrbars = 0;
set_key = 0;
set_linestyle = "solid";
+   set_axes = 0;
+   xaxis = "x1";
+   yaxis = "y1";

more_opts = 1;

***************
*** 155,160 ****
--- 158,169 ----
set_points = 1;
set_symbol = 1;
symbol = "4";
+     elseif (strcmp (char, "X"))
+       set_axes = 1;
+       xaxis = "x2";
+     elseif (strcmp (char, "Y"))
+       set_axes = 1;
+       yaxis = "y2";
elseif (strcmp (char, ";"))  # title mode.
set_key = 1;
working = 1;
***************
*** 233,238 ****
--- 242,251 ----
endif
elseif (set_symbol)
fmt = strcat (fmt, " 1 ", symbol);
+   endif
+
+   if (set_axes)
+     fmt = strcat (fmt, " ax ", xaxis, yaxis);
endif

if (set_key)

On Wed, Aug 07, 2002 at 10:29:00AM -0300, marcelo wrote:
> Dear Mr/Mrs octave users
>
> I'm newbie to octave, but i'm grateful to be using this
> free software!
> my question is about plotting data with different scales...
> like
> x=rand(100,1)
> y1=10.*x
> y2=100.*x
> mplot() #using left axes with same scale
> plot()#just plot x and y1
>
> so, i just plot to left axes with range(0:1) and right axes with
> range(10:100)
> Is there some function or script to do this??
> Thanks a lot for any help
> sorry for my poor english!!
> --
> Marcelo Alexandre Bruno - Pos-graduacao Oceanografia Biologica
> Departamento de Oceanografia -  Laboratorio de Ecologia do Ictioplancton
> (0xx53) 2336529 - Rio Grande - RS - BRAZIL
>
>
>
> -------------------------------------------------------------
> Octave is freely available under the terms of the GNU GPL.
>
> Octave's home on the web:  http://www.octave.org
> How to fund new projects:  http://www.octave.org/funding.html
> Subscription information:  http://www.octave.org/archive.html
> -------------------------------------------------------------
>

-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------

```