Re: setting up axes in IDL [message #12039] |
Sun, 14 June 1998 00:00 |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Tony Casey (caseyta@mail.auburn.edu) writes:
> OK, I'm ust learning, here's my problem:
> I have an output file in "TVSCL" type, and some lines drawn with "PlotS" I
> need to set up an axis system with ticks and such centered in the middle of
> the output. Please help.
Well, what you want to do is not at all simple when you don't
know too much about IDL. You could continue to build your
own axes with the PlotS command, but that is a bit complicated.
It would be better to use the Axis command to create the axes,
but you need a data coordinate system for that and the TVScl
command doesn't provide one.
Then you have the problem of how to put the image in the
display window, and that is complicated by the size of
the display window and the size of the image, etc. and
before you know it you have a complicated piece of code
lying around to do something that should be simple.
So here is what I would do. Go to my web page and get
the TVImage program. This will help you position your
image in the window without worrying about the size
of the image or the window. (TVImage is more
closely related to TV than to TVScl, however, so
be sure you scale the image data before you pass it
to TVImage. You can do this with BytScl and you should
probably get in the habit of doing it anyway, since using
TVScl sooner or later ends up a bad idea.)
Then use this little example program to put axes
through the center of the image. The XRange and
YRange keywords can be used to set the endpoints of
the axes. Notice that the Plot command doesn't put
anything at all on the display. I use it only to
set up the proper data coordinate space for the
Axis commands later on. You use the program with
your image like this:
Example, myimage, XRange=[-1,1], YRange=[0,100]
You can find a lot of programming tips on my web page
and more in my book, if you are interested.
Best Regards,
David
********************************************************
PRO Example, image, XRange=xrange, YRange=yrange
; Open an image file if necessary.
IF N_Params() EQ 0 THEN BEGIN
file = Filepath(SubDirectory=['examples','data'], $
'worldelv.dat')
OpenR, lun, file, /Get_Lun
image = BytArr(360, 360)
ReadU, lun, image
Free_Lun, lun
ENDIF
; Check keyword parameters.
IF N_Elements(xrange) EQ 0 THEN xrange = [0,100]
IF N_Elements(yrange) EQ 0 THEN yrange = [0,100]
; Make vectors for plot.
x = Findgen(100)*xrange[1]/99.0 + xrange[0]
y = Findgen(100)*yrange[1]/99.0 + yrange[0]
; Create a data coordinate space.
thisPosition = [0.15, 0.15, 0.85, 0.85]
Plot, y, x, Position=thisPosition, /NoData, $
XStyle=4, YStyle=4, XRange=xrange, YRange=yrange
; Display the image.
TVImage, image, Position=position
; Add axes.
Axis, /XAxis, 0.5, 0.5, /Normal, XRange=xrange
Axis, /YAxis, 0.5, 0.5, /Normal, XRange=yrange
END
*******************************************************
David Fanning, Ph.D.
Fanning Software Consulting
E-Mail: davidf@dfanning.com
Phone: 970-221-0438
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|