comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: 2 variables on same plot?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: 2 variables on same plot? [message #24841] Thu, 26 April 2001 05:39 Go to previous message
colinr is currently offline  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
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: subtle but important
Next Topic: Re: subtle but important

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 04:40:51 PDT 2025

Total time taken to generate the page: 0.72155 seconds