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

Home » Public Forums » archive » Specifying Log Axis Tick Marks
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Specifying Log Axis Tick Marks [message #46139] Fri, 28 October 2005 18:19 Go to previous message
JD Smith is currently offline  JD Smith
Messages: 850
Registered: December 1999
Senior Member
The topic of how to specify tick values for plots with log axes has
come up on the list multiple times over the past several years, with
no satisfying conclusion. Suppose you are motivated to create a
logarithmic plot spanning less than one decade:

IDL> plot,.5+randomu(sd,100)*.3,.4+randomu(sd,100)*.3,/XLOG,/YLOG ,PSYM=4

That results in a very unsatisfying grouping of points up in the top
right of the plot. You can of course choke down the axis ranges, like
so:

plot,.5+randomu(sd,100)*.3,.4+randomu(sd,100)*.3,/XLOG,/YLOG , $
PSYM=4,XRANGE=[.5,.8],YRANGE=[.4,.7],/XSTYLE,/YSTYLE

but you're left with two completely unlabeled axes. Aha, you say,
I'll just increase the number of tick marks:

plot,.5+randomu(sd,100)*.3,.4+randomu(sd,100)*.3,/XLOG,/YLOG , $
PSYM=4,XRANGE=[.5,.8],YRANGE=[.4,.7],/XSTYLE,/YSTYLE,XTICKS= 5,YTICKS=5

Hmm, that's not exactly what you might like: fairly random values have
been chosen for the axes. What about labeling them yourself? That
should do the trick:

plot,.5+randomu(sd,100)*.3,.4+randomu(sd,100)*.3,/XLOG,/YLOG ,$
PSYM=4,XRANGE=[.5,.8],YRANGE=[.4,.7],/XSTYLE,/YSTYLE, $
XTICKS=3,XTICKV=[.5,.7,.8],YTICKS=4,YTICKV=[.4,.5,.6,.7]
% PLOT: Data coordinate system not established.
% Execution halted at: $MAIN$

Ouch! So what's happening? It appears that for logarithmic plots,
the data coordinate system isn't yet set, probably because the ticks
are evaluated before the log coordinate frame is setup. Hence, you
cannot specify the locations of the tick marks. What to do? Draw
your own axes by hand using plots and xyouts? Perish the thought. It
turns out you can simply skip the axes when first plotting, and use
AXIS to add them straightforwardly after the coordinate frame has been
set:


plot,.5+randomu(sd,100)*.3,.4+randomu(sd,100)*.3,/XLOG,/YLOG ,$
PSYM=4,XRANGE=[.5,.8],YRANGE=[.4,.7],XSTYLE=5,YSTYLE=5

xtitle='My X Title' & ytitle='My Y Title'

for i=0,1 do begin
axis,XAXIS=i,/XLOG,/XSTYLE,XRANGE=10.^!X.CRANGE, $
XTICKFORMAT=i?'(A1)':'',XTICKS=3, $
XTICKV=[.5,.7,.8],XMINOR=10,XTITLE=i?'':xtitle
axis,YAXIS=i,/YLOG,/YSTYLE,YRANGE=10.^!Y.CRANGE, $
YTICKFORMAT=i?'(A1)':'',YTICKS=4, $ $
YTICKV=[.4,.5,.6,.7],YMINOR=10.,YTITLE=i?'':ytitle
endfor

And there you have it, specified logarithmic major axes ticks, with some
minor axis tick marks thrown in for good measure. Should we have to do
this? Probably not. But at least there is an option that doesn't require
computing your own axis marks from scratch.

JD


P.S. Why would you want to plot LOG-LOG when your data span such a
small range? One good reason is when you'd like to indicate a fixed
ratio by drawing a single representative line. On LOG-LOG plots, a
fixed length interval implies a fixed ratio; not so in linear space.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Converting Doubles to Strings
Next Topic: Converting Doubles to Strings

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

Current Time: Fri Oct 10 16:09:50 PDT 2025

Total time taken to generate the page: 1.04305 seconds