[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Log axes using object graphics



I've blundered around a bit, and I think I've sorted out one problem and
found a more devious one.

In general, I think the method to plot logarithmic axis is as follows:

Set the log parameter of the IDLgrAxis object to 1
Set the range parameters of the IDLgrAxis objects to the actual range you
want (eg [10,10000])
Retrieve the crange values from the axis (which will be the log of the range
you passed in)
Use these crange values to calculate the coordinate conversion factors.
Set the xcoord_conv parameters of the axis and plot objects to the
calculated factors.
Set the range parameters of the plot to the crange values retrieved from the
axes.

Fine, this is more or less like the linear plot case, with the exception
that you have to keep in mind that you pass the 'actual' range into the axis
objects, but use the CRANGE values for the plot objects and coordinate
convertion factors.


Now, the problem is that the machine hangs when I try to plot a logarithmic
range that is approximately one order of magnitude and spans only one power
of 10 -ie [500,5000]

Try the following procedure called 'Objtest.pro'. First, execute it as is.
Then try un-commenting the 2nd line. On my machine it hangs at
"thisWindow->Draw, thisView"

Any ideas?

Thanks,
Brad

--------------------------------------------------------

FUNCTION BGNorm_range, range, Position=position
 IF (N_Elements(position) EQ 0) THEN position = [0d, 1d] ELSE $
  position=double(position)
 range = double(range)
 scale = [((position[0]*range[1])-(position[1]*range[0])) / $
  (range[1]-range[0]), (position[1]-position[0])/(range[1]-range[0])]
RETURN, scale
END

pro objtest
 xrange=[10,1000]
; xrange=[500,5000]    ;this is the range that crashes the Draw method.
 yrange=[-2,2]
 xlog=1
 ylog=0
 x=findgen(10000)+2
 y=sin(x)

 xAxis1 = Obj_New("IDLgrAxis", 0, Ticklen=0.025, Minor=4, $
    color=[255,255,255], Range=xrange, Location=[1000, 0 ,0],$
    /Exact, log=xlog, name='xaxis1')
 xAxis2 = Obj_New("IDLgrAxis", 0, Ticklen=0.025, Minor=4, $
    /NoText, color=[255,255,255], Range=xrange, TickDir=1, $
    Location=[1000, 1, 0], /Exact, log=xlog, name='xaxis2')
 yAxis1 = Obj_New("IDLgrAxis", 1, Ticklen=0.025, Minor=4,$
    color=[255,255,255], Range=yrange, Location=[0, 1000, 0], $
    /Exact, log=ylog, name='yaxis1')
 yAxis2 = Obj_New("IDLgrAxis", 1, Ticklen=0.025, Minor=4, $
    /NoText, color=[255,255,255], Range=yrange, TickDir=1,$
    Location=[1, 1000, 0], /Exact, log=ylog, name='yaxis2')

 xAxis1->GetProperty, CRange=xrange
 yAxis1->GetProperty, CRange=yrange

 xs = BGNorm_range(xrange)
 ys = BGNorm_range(yrange)
 xAxis1->SetProperty, XCoord_Conv=xs
 xAxis2->SetProperty, XCoord_Conv=xs
 yAxis1->SetProperty, YCoord_Conv=ys
 yAxis2->SetProperty, YCoord_Conv=ys

 ;use log values for the plot
 if xlog ne 0 then x=alog10(x)
 if ylog ne 0 then y=alog10(y)
 p1 = Obj_New("IDLgrPLOT", x, y,name='p1',XCoord_Conv=xs,$
    YCoord_Conv=ys,color=[255,255,255], xrange=xrange,$
    yrange=yrange)

 thisModel = Obj_New('IDLgrModel')
 thisModel->add,xAxis1
 thisModel->add,xAxis2
 thisModel->add,yAxis1
 thisModel->add,yAxis2
 thisModel->add,p1

 Container1 = Obj_New('IDL_Container')

 thisWindow=Obj_new('IDLgrWindow')
 thisView = Obj_New('IDLgrView', Viewplane_Rect=[-.2, -.2, 1.3, 1.3], $
    Location=[0,0], Color=[0,0,0])
 thisView->Add, thisModel
 Container1->add,thisView
 Container1->add,thisWindow
 Container1->add,thisModel

print,'drawing'
 thisWindow->Draw, thisView
print,'done'

 result=dialog_message('Hit OK to continue',/info)
 obj_destroy,Container1
end