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
|