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 
Switch to threaded view of this topic Create a new topic Submit Reply
Specifying Log Axis Tick Marks [message #46139] Fri, 28 October 2005 18:19 Go to next 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.
Re: Specifying Log Axis Tick Marks [message #46150 is a reply to message #46139] Mon, 07 November 2005 12:52 Go to previous messageGo to next message
JD Smith is currently offline  JD Smith
Messages: 850
Registered: December 1999
Senior Member
On Mon, 07 Nov 2005 13:49:33 -0700, JD Smith wrote:

> On Mon, 07 Nov 2005 20:12:46 +0100, Reimar Bauer wrote:
>
>> [quoted text muted]
>
> Right you are. Any explanation?

Oh, never mind, they asked for "intervals", not ticks. And were quite
particular about that, it seems.

JD
Re: Specifying Log Axis Tick Marks [message #46151 is a reply to message #46139] Mon, 07 November 2005 12:49 Go to previous messageGo to next message
JD Smith is currently offline  JD Smith
Messages: 850
Registered: December 1999
Senior Member
On Mon, 07 Nov 2005 20:12:46 +0100, Reimar Bauer wrote:

> XTICKS=2 and YTICKS=3
>
> does it

Right you are. Any explanation?

Thanks,

JD
Re: Specifying Log Axis Tick Marks [message #46156 is a reply to message #46139] Mon, 07 November 2005 11:12 Go to previous messageGo to next message
R.Bauer is currently offline  R.Bauer
Messages: 1424
Registered: November 1998
Senior Member
Hi JD,

XTICKS=2 and YTICKS=3

does it

cheers

Reimar

--- snipped ---

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:
Re: Specifying Log Axis Tick Marks [message #46243 is a reply to message #46150] Mon, 07 November 2005 22:46 Go to previous message
R.Bauer is currently offline  R.Bauer
Messages: 1424
Registered: November 1998
Senior Member
JD Smith wrote:

> On Mon, 07 Nov 2005 13:49:33 -0700, JD Smith wrote:
>
>> On Mon, 07 Nov 2005 20:12:46 +0100, Reimar Bauer wrote:
>>
>>> [quoted text muted]
>>
>> Right you are. Any explanation?
>
> Oh, never mind, they asked for "intervals", not ticks. And were quite
> particular about that, it seems.
>
> JD

It is just the wrong parameter name. Wrong nameing does happen to all of us
and it is sometimes very hard to change a name like this.


cheers
Reimar
  Switch to threaded view of this topic Create a new topic Submit Reply
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 10:22:15 PDT 2025

Total time taken to generate the page: 2.07917 seconds