Re: 2 variables on same plot? [message #24841] |
Thu, 26 April 2001 05:39  |
colinr
Messages: 30 Registered: July 1999
|
Member |
|
|
On Wed, 25 Apr 2001 16:07:20 -0600,
Cathy Smith <cas@cdc.noaa.gov> wrote:
> Hi all,
>
> How do I plot 2 variables on 1 plot? They each have vastly
> different ranges. I believe I am supposed to use AXIS but I can't seem
> to get the 2nd plot to be scaled correctly.
>
>
> xt=indgen(365)
> plot,xt(0:90),omega(0:90),xstyle=8,ystyle=8
> axis,yrange=[0,11],ystyle=1,/save,yaxis=1,xaxis=0
> oplot,xt(0:90),prate(0:90),linestyle=2
>
> The 2nd y axis has values from 0 to 10 and the data ranges from 0 to 10
> but it is plotted from 0 to .001 or something like that.
>
> thanks
> Cathy Smith
Here's a routine I use to do this sort of thing. Sorry it's not
documented and I haven't used it for a while so I can't
remember _exactly_ what it does but try something like
IDL> plot_scales,[1,2,3,4],[1,7,6,5],[12,3,4,7]*1.d-8,ystyles_l=1 ,ystyles_r=2
You can also pass labels to all four axes and make multiple plots on each
axis.
pro plot_scales,x,y_l,y_r,ytitle_l=ytitle_l,ytitle_r=ytitle_r,$
xscale_top=xscale_top,xtitle_b=xtitle_b,xtitle_top=xtitle_to p,$
ystyles_l=ystyles_l,ystyles_r=ystyles_r,xrange=xrange,_extra =e
;
save_environment
;
size_l=size(y_l)
size_r=size(y_r)
if size_l(0) eq 1 then begin
n_l=1
y_l=transpose(y_l)
endif
if size_l(0) eq 2 then n_l=size_l(1)
if size_r(0) eq 1 then begin
n_r=1
y_r=transpose(y_r)
endif
if size_r(0) eq 2 then n_r=size_r(1)
;
n_l_2=n_elements(ystyles_l)
n_r_2=n_elements(ystyles_r)
;
; Make initial plot
;
pmulti_old=!p.multi
nm=pmulti_old(0)
if n_l_2 ne 0 then !p.linestyle=ystyles_l(0)
if n_elements(ytitle_l) ne 0 then !y.title=ytitle_l
if n_elements(xtitle_b) ne 0 then !x.title=xtitle_b
if n_elements(xrange) ne 0 then !x.range=xrange
if n_elements(xscale_top) eq 0 then begin
!x.margin=[10,6]
!y.margin=[4,4]
plot,x,y_l(0,*),ystyle=8,_extra=e
endif else begin
!x.margin=[8,8]
!y.margin=[4,4]
plot,x,y_l(0,*),ymargin=[4,4],xmargin=[8,8],ystyle=8,xstyle= 8,_extra=e
xrange_top=xscale_top*!x.crange
if n_elements(xtitle_top) ne 0 then !x.title=xtitle_top
axis,xaxis=1,xrange=xrange_top
endelse
;
; plot remaining left-axis plots
;
if n_l gt 1 then for jj=2,n_l do begin
if n_l_2 ne 0 then !p.linestyle=ystyles_l(jj-1)
oplot,x,y_l(jj-1,*)
endfor
;
; plot first right-axis plot
;
!p.multi=pmulti_old
if nm eq 0 then !p.multi(0)=pmulti_old(1)*pmulti_old(2)
if !p.multi(0) eq 0 then !p.multi(0)=1
if n_r_2 ne 0 then !p.linestyle=ystyles_r(0)
plot,x,y_r(0,*),xstyle=4,ystyle=4,_extra=e
if n_elements(ytitle_r) ne 0 then !y.title=ytitle_r
axis,yaxis=1,yrange=!y.crange,ystyle=1,_extra=e
;
; do remaining right hand plots
;
if n_r gt 1 then for jj=2,n_r do begin
if n_r_2 ne 0 then !p.linestyle=ystyles_r(jj-1)
oplot,x,y_r(jj-1,*)
endfor
end
--
Colin Rosenthal
Astrophysics Institute
University of Oslo
|
|
|
Re: 2 variables on same plot? [message #24842 is a reply to message #24841] |
Thu, 26 April 2001 03:44   |
Martin Schultz
Messages: 515 Registered: August 1997
|
Senior Member |
|
|
Cathy Smith wrote:
>
> Hi all,
>
> How do I plot 2 variables on 1 plot? They each have vastly
> different ranges. I believe I am supposed to use AXIS but I can't seem
> to get the 2nd plot to be scaled correctly.
>
> xt=indgen(365)
> plot,xt(0:90),omega(0:90),xstyle=8,ystyle=8
> axis,yrange=,ystyle=1,/save,yaxis=1,xaxis=0
> oplot,xt(0:90),prate(0:90),linestyle=2
>
> The 2nd y axis has values from 0 to 10 and the data ranges from 0 to 10
> but it is plotted from 0 to .001 or something like that.
>
> thanks
> Cathy Smith
>
> --
> "A round of victory lattes for everyone!!!!"
>
> ############################################################ ######
> # NOAA-CIRES Climate Diagnostics Center #
> # U of C Campus Box 216 Boulder, CO 80309-0216 #
> # e-mail cas@cdc.noaa.gov web:http://www.cdc.noaa.gov/~cas #
> # phone (303)497-6263 fax:(303)497-6449 #
> ############################################################ ######
Can't see anything wrong with your code (except for using () instead
of [] for array indexing). The procedure below does what it should, I
think. Try a statement like
print, min(prate(0:90),max=mm),mm
to see what your data range is really like.
In the future: please post code examples that work by cut&paste - th
eeasier it is for people to try out your code, the more likely will
you get an answer.
Cheers,
Martin
PRO second_axis
;; create dummy data
xt=indgen(365)
omega = sin(!DTOR*xt)
prate = 10.*cos(4.*!DTOR*xt)*cos(4.*!DTOR*xt)*exp(-xt/100.)
;; plot
plot,xt,omega,xstyle=8,ystyle=8
axis,yrange=,ystyle=1,/save,yaxis=1,xaxis=0
oplot,xt[0:90],prate[0:90],linestyle=2
END
--
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [[[[[[[
[[ Dr. Martin Schultz Max-Planck-Institut fuer Meteorologie [[
[[ Bundesstr. 55, 20146 Hamburg [[
[[ phone: +49 40 41173-308 [[
[[ fax: +49 40 41173-298 [[
[[ martin.schultz@dkrz.de [[
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [[[[[[[
|
|
|
Re: 2 variables on same plot? [message #24912 is a reply to message #24842] |
Fri, 27 April 2001 08:25  |
Cathy Smith
Messages: 3 Registered: January 2001
|
Junior Member |
|
|
Martin Schultz wrote:
>
> Can't see anything wrong with your code (except for using () instead
> of [] for array indexing). The procedure below does what it should, I
> think. Try a statement like
>
> print, min(prate(0:90),max=mm),mm
>
> to see what your data range is really like.
>
> In the future: please post code examples that work by cut&paste - th
> eeasier it is for people to try out your code, the more likely will
> you get an answer.
>
> Cheers,
>
> Martin
thanks. I'll make sure the code I post will actually work in the future.
It turns out it did work as written (and I had deleted the print max
statement statement). However, I had to leave idl and come back in
again.
I'm not quite sure why but I guess I should always try that first.
Cathy S.
|
|
|