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

Home » Public Forums » archive » Flipping and combining plots
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Flipping and combining plots [message #30888] Thu, 23 May 2002 08:28 Go to next message
Wayne Landsman is currently offline  Wayne Landsman
Messages: 117
Registered: January 1997
Senior Member
I want to create an X-Y scatter plot, and have an associated plot of the
Y
histogram values placed snug next to it. This means that the
histogram plot needs to be flipped 90 degrees so that the (original)
X-axis of
the histogram is snug against the right Y axis of the scatter plot.
My
approach has been to use the /XYEXCH keyword of the T3D procedure to
flip the X
and Y axis. This seems to work O.K. but the plot annotation now looks
correct
only if viewed through a mirror (for !P.FONT=-1 or 1) or is not
positioned
correctly (for !P.FONT = 0). I suppose that I could suppress the
annotation and then rewrite it myself without the T3D keyword present.

But I have a suspicion that I am making the problem too complicated and
that
there is any easier way to make the plot, perhaps without using T3D.
Any
ideas?

My test code is below. (The histogramming may not be quite right, but
I
wanted to make the program self-contained.)

Thanks, --Wayne Landsman landsman@mpb.gsfc.nasa.gov


pro test ;Combine a scatter + Y histogram plot
x = indgen(100) ;X axis
y = abs(randomn(seed,100)*10) ;Create scattered Y data
xdivide = 0.7 ;Scatter plot is 0.7 of X plot area, histogram plot is
0.3
plot,x,y,/nodata ;Set up plotting coordinates but don't plot

;Get left and right margins in normalized coordinates
margins = [min(!x.window)-min(!x.region), $
min(!y.window)-min(!y.region), $
max(!x.region)-max(!x.window), $
max(!y.region)-max(!y.window)]

;Get total plot size

ysize = 1. - margins[1] - margins[3]
xsize = 1. - margins[0] - margins[2]


;Set up plot position for scatter plot

pos = [0,0,xdivide*xsize,ysize] + $
[margins[0],margins[1],margins[0],margins[1]]

plot,x,y,psym=1,pos=pos

;Now set up plot position for (rotated) histogram plot, flip X and Y
values

Pos = [ 0, xdivide*xsize,ysize,xsize] + $
[margins[1],margins[0],margins[1],margins[0]]

T3D,/reset,/xyexch ;Histogram plot will have X and Y values
exchanged

h = histogram(y,min=!Y.crange[0],max = !Y.crange[1]) ;Histogram of Y
values
n = !Y.crange[1] - !y.crange[0]
xx = !Y.crange[0] + indgen(n) ;Xrange for histogram
n = N_elements(xx)
xx = [0,xx, xx[n-1]+1 ] + 0.5
yy = [0,histogram(y),0]

plot,/t3d,xx,yy,/noerase,pos=pos,psym=10,xtit = ' ', /noclip, $
xticks = 2,xtickname = [' ',' ',' '],xrange=!Y.crange,/xsty
return
end
Re: Flipping and combining plots [message #30967 is a reply to message #30888] Fri, 24 May 2002 06:52 Go to previous messageGo to next message
Don J Lindler is currently offline  Don J Lindler
Messages: 19
Registered: April 2001
Junior Member
Try the updated code below where the x and y axes are switched
it the call to plot and the PSYM=10 is done by dupplicating the x and y
values.
Also, the first plot was modified to not label the last x-axis value so that
it
does not overlap the first label of the second plot.

Don Lindler
lindler@rockit.gsfc.nasa.gov

pro test ;Combine a scatter + Y histogram plot
x = indgen(100) ;X axis
y = abs(randomn(seed,100)*10) ;Create scattered Y data
xdivide = 0.7 ;Scatter plot is 0.7 of X plot area, histogram plot is 0.3
plot,x,y,/nodata,xtick_get=v ;Set up plotting coordinates but don't plot

;Get left and right margins in normalized coordinates
margins = [min(!x.window)-min(!x.region), $
min(!y.window)-min(!y.region), $
max(!x.region)-max(!x.window), $
max(!y.region)-max(!y.window)]

;Get total plot size

ysize = 1. - margins[1] - margins[3]
xsize = 1. - margins[0] - margins[2]


;Set up plot position for scatter plot

pos = [0,0,xdivide*xsize,ysize] + $
[margins[0],margins[1],margins[0],margins[1]]

plot,x,y,psym=1,pos=pos,xtickname=[replicate('',n_elements(v )-1),' ']

;Now set up plot position for (rotated) histogram plot, flip X and Y values

Pos = [ xdivide*xsize,0,xsize,ysize] + $
[margins[0],margins[1],margins[0],margins[1]]

h = histogram(y,min=!Y.crange[0],max = !Y.crange[1]) ;Histogram of Y
values
n = !Y.crange[1] - !y.crange[0]
xx = !Y.crange[0] + indgen(n) ;Xrange for histogram
xx = [transpose(xx)-0.5,transpose(xx)+0.5]
yy = [transpose(h),transpose(h)]
plot,yy,xx,yrange = !y.crange,ystyle=1,ytickname=[' ',' ','
'],yticks=2,/noerase, $
pos = pos
return
end




"Wayne Landsman" <landsman@mpb.gsfc.nasa.gov> wrote in message
news:3CED0A80.950535C2@mpb.gsfc.nasa.gov...
>
> I want to create an X-Y scatter plot, and have an associated plot of the
> Y
> histogram values placed snug next to it. This means that the
> histogram plot needs to be flipped 90 degrees so that the (original)
> X-axis of
> the histogram is snug against the right Y axis of the scatter plot.
> My
> approach has been to use the /XYEXCH keyword of the T3D procedure to
> flip the X
> and Y axis. This seems to work O.K. but the plot annotation now looks
> correct
> only if viewed through a mirror (for !P.FONT=-1 or 1) or is not
> positioned
> correctly (for !P.FONT = 0). I suppose that I could suppress the
> annotation and then rewrite it myself without the T3D keyword present.
>
Re: Flipping and combining plots [message #77064 is a reply to message #30888] Tue, 02 August 2011 09:22 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Dave writes:

> I can plot my scatter plot easily enough, and I can plot a rotated histogram using:
>
> h = histogram(alog10(y),min=min(alog10(y)),max = max(alog10(y)), $
> binsize=best_bin(alog10(y)),loc=loc)
> t3d,/reset,/xyexch
> plot,10^loc,h,psym=10,/xlog,/t3d ;,pos=[0.05,0.05,0.9,0.99]
>
> The difficulty comes in when I uncomment the position keyword in the last plot statement. I'd like the scatter plot to take up ~70% of the plot window, but when I squeeze the histogram, it simply doesn't plot. The values listed here will plot almost the entire histogram, but as I begin increasing the pos[1] value (shrinking the histogram into the right side of the plot window), the histogram itself begins disappearing from the bottom of the plot. By the time I use
pos=[0.05,0.7,0.9,0.99] (my desired position values) I only get blank axes.
>
> Does anyone know why this happens, and how I can overcome it?

/NoClip?

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Flipping and combining plots [message #77066 is a reply to message #30967] Tue, 02 August 2011 09:06 Go to previous message
Dave[5] is currently offline  Dave[5]
Messages: 11
Registered: July 2010
Junior Member
Hello, I am trying to accomplish this same task, but I'm not having any luck adapting the approach outlined here.

I can plot my scatter plot easily enough, and I can plot a rotated histogram using:

h = histogram(alog10(y),min=min(alog10(y)),max = max(alog10(y)), $
binsize=best_bin(alog10(y)),loc=loc)
t3d,/reset,/xyexch
plot,10^loc,h,psym=10,/xlog,/t3d ;,pos=[0.05,0.05,0.9,0.99]

The difficulty comes in when I uncomment the position keyword in the last plot statement. I'd like the scatter plot to take up ~70% of the plot window, but when I squeeze the histogram, it simply doesn't plot. The values listed here will plot almost the entire histogram, but as I begin increasing the pos[1] value (shrinking the histogram into the right side of the plot window), the histogram itself begins disappearing from the bottom of the plot. By the time I use pos=[0.05,0.7,0.9,0.99] (my desired position values) I only get blank axes.

Does anyone know why this happens, and how I can overcome it?

Thanks,
Dave
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: multi-color (time-series) line plot
Next Topic: Eclipse

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

Current Time: Wed Oct 08 09:13:13 PDT 2025

Total time taken to generate the page: 0.00690 seconds