IDLgrAxis question. [message #38076] |
Thu, 19 February 2004 12:26  |
savoie
Messages: 68 Registered: September 1996
|
Member |
|
|
Gurus,
O.k. I've been pulling hair and beating my head over this for a while, and I
think if I ask, someone here will probably be able to tell me right away. I
want to be able to change the range of an axis from within a widget program.
I am doing this with the setProperty procedures of the axis and plot. After
I do this, the yfonts get all screwy. (that's the technical term.)
I'm running into this problem on IDL Version 6.0 (linux x86 m32).
I have just taken Ronn Kling's example program and hacked it to show you what
I mean.
Please tell me what I'm doing wrong before I get any balder?
Thanks so much
Matt
;; Here it is ....
pro plot_axis_weirdness
;; example program for plot objects from Kling's book originally, modified
;; to ask a question
array = findgen(180)
x = array
y = Sin(array/5.) / Exp(array/50.)
theFont = Obj_New('IDLgrFont', size = 8)
oWindow = obj_new('IDLgrWindow', dimension = [400, 400], renderer = 1, $
retain = 2, title = 'Plot Object example')
oView = obj_new('IDLgrView', $
VIEWPLANE_RECT = [-.3, -.3, 1.4, 1.6], $
color = [255, 255, 255])
oModel = obj_new('IDLgrModel')
oPlot = obj_new('IDLgrPlot', x, y)
oPlot -> getProperty, xrange = xrange, yrange = yrange
print, yrange, xrange
xs = normalize(xrange)
ys = normalize(yrange)
oPlot -> setProperty, xcoord_conv = xs, ycoord_conv = ys
oModel -> add, oPlot
oView -> add, oModel
oTextX = obj_new('IDLgrText', 'X Axis', FONT=theFont)
oAxisX = obj_new('IDLgrAxis', 0, range = xrange, xcoord_conv = xs, /EXACT, $
title = oTextX)
;;add it to the model
oModel -> add, oAxisX
;;create a text object
oTextY = obj_new('IDLgrText', 'Y Axis', FONT = theFont)
;;create an axis object
oAxisY = obj_new('IDLgrAxis', 1, range = yrange, $
ycoord_conv = ys, exact = 1, $
title = oTextY)
;;add it to the model
oModel -> add, oAxisY
oWindow -> draw, oView ;;have to redraw the view to see the changes
oWindow -> show, 1 ;;now push it to the top
print, 'press return to change the yrange'
r = get_kbrd(1)
oAxisY -> GetProperty, crange = range
print, range
new_range = [range[0]-4, range[0]+4]
oAxisY -> SetProperty, range = new_range, /EXACT
;; just to verify
oAxisY -> GetProperty, crange = range
print, range
new_Yscale = normalize(range)
oAxisY -> SetProperty, YCOORD_CONV = new_Yscale
oPlot -> SetProperty, YCOORD_CONV = new_Yscale
oWindow -> draw, oView
oWindow -> show, 1
print, 'press return to end the program'
r = get_kbrd(1)
;clean up the objects
obj_destroy, oWindow
obj_destroy, oView
obj_destroy, oModel
obj_destroy, oPlot
obj_destroy, oAxisX
obj_destroy, oAxisY
obj_destroy, oTextX
obj_destroy, oTextY
return
end
--
Matthew Savoie - Scientific Programmer
National Snow and Ice Data Center
(303) 735-0785 http://nsidc.org
|
|
|
Re: IDLgrAxis question. [message #38150 is a reply to message #38076] |
Sat, 21 February 2004 08:21   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Matt Savoie writes:
> O.k. I've been pulling hair and beating my head over this for a while, and I
> think if I ask, someone here will probably be able to tell me right away. I
> want to be able to change the range of an axis from within a widget program.
> I am doing this with the setProperty procedures of the axis and plot. After
> I do this, the yfonts get all screwy. (that's the technical term.)
>
> I'm running into this problem on IDL Version 6.0 (linux x86 m32).
>
> I have just taken Ronn Kling's example program and hacked it to show you what
> I mean.
>
> Please tell me what I'm doing wrong before I get any balder?
I'm not sure baldness (or more people wanting to love and
and make commitments to one another, to chose another problem
in the news) is the biggest problem we have in the world,
but I'll try to do my part. :-)
When you change the axis range, you must also recompute
the "dimensions" of the characters used to label the axis,
because the "size" of the labels is based on the range of
the data. Here is an article about the problem:
http://www.dfanning.com/ographics_tips/font_dimensions.html
I fixed your program by changing this:
;;create a text object
oTextY = obj_new('IDLgrText', 'Y Axis', FONT = theFont)
;;create an axis object
oAxisY = obj_new('IDLgrAxis', 1, range = yrange, $
ycoord_conv = ys, exact = 1, $
title = oTextY)
;;add it to the model
oModel -> add, oAxisY
To this:
;;create a text object
oTextY = obj_new('IDLgrText', 'Y Axis', FONT = theFont, $
Recompute_Dimensions=2)
;;create an axis object
oAxisY = obj_new('IDLgrAxis', 1, range = yrange, $
ycoord_conv = ys, exact = 1, $
title = oTextY)
;; get the axis labels so you can recompute these labels, too.
oAxisY -> GetProperty, TickText=labels
labels -> SetProperty, Recompute_Dimensions=2
;;add it to the model
oModel -> add, oAxisY
Cheers,
David
P.S. Let's just say I'm interested in the psychology of someone who
finds "I love you" to be infinitely more frightening than "I'm a
war president."
P.S.S. Before you write in, I'm aware this is the wrong forum, etc.,
etc. It's just that when I get back from a trip late at night, it is
my habit to read the newspapers that have accumulated in my absence.
It's just on my mind, and seems more important to me this morning
than IDL programming. I'll probably get my priorities straightened
out again in a day or two. :-)
--
David Fanning, Ph.D.
Fanning Software Consulting
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
Re: IDLgrAxis question [message #65502 is a reply to message #38076] |
Thu, 05 March 2009 09:53  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
j.anctil@att.net writes:
> I am implementing some code in IDL which utilize the IDLgrAxis object.
> If I have an axis range which spans from say from -0.3 to 0.5 and
> would like to have the tick marks placed in such a way that the zero
> value of the axis is always labeled, how do I write code for that? Of
> course the limits could be any negative value to any positive value.
>
> The direct graphics CONTOUR command will do this automatically, and I
> need to be able to replicate this.
It seems to me the IDLgrAxis does this automatically.
Do you have some evidence that it does not?
IDL> o = obj_new('idlgraxis', 1, range=[-0.3, 0.5])
IDL> xobjview, o
Cheers,
David
--
David Fanning, Ph.D.
Coyote's Guide to IDL Programming (www.dfanning.com)
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|