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

Home » Public Forums » archive » Axis labeling trickery
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Axis labeling trickery [message #85781] Fri, 06 September 2013 16:18 Go to previous message
Paul Levine is currently offline  Paul Levine
Messages: 29
Registered: February 2008
Junior Member
I am plotting some irregularly-spaced observations over 10 years, and I
would like my x-axis to be labeled with exactly those 10 years, with a
tick mark at the beginning of every year.

When I use XTickFormat='Label_Date' and XTicks = 10, the tick marks are
in the right place (January 1) but of course I then have 11 tick marks,
including a label with the year after my 10-year interval. My current
workaround is to draw the labels that I want to see with xyouts (or
cgText), but this leaves me with other problems, so I am hoping there
is a non-workaround way to make the y-axis labels as I want from the
get go.

What follows are two examples, the first of which draws the problematic
labels, the second uses my workaround. The first two lines of each
example generate some random data that simulates the data I'm working
with. Both examples use coyote graphics procedures, but should work
the same with plot for cgPlot and xyouts for cgText

Example 1:

time = timegen(120,start=julday(1,1,2003), units='M', step_size=1)
data = 20*randomu(seed,n_elements(time))-10
void = Label_Date(Date_Format='%Y')
cgPlot, time, data, xrange=[julday(1,1,2003),julday(12,31,2012)],
XTickFormat='Label_Date', XTicks = 10

In this example, my y-axis labels include 2003 through 2013, when I
would like for it to stop at 2012


Example 2:

time = timegen(120,start=julday(1,1,2003), units='M', step_size=1)
data = 20*randomu(seed,n_elements(time))-10
void = Label_Date(Date_Format=' ')
years = indgen(10)+2003
cgPlot, time, data, xrange=[julday(1,1,2003),julday(12,31,2012)],
XTickFormat='Label_Date', XTicks = 10
xoff = 2 ; sets how far to the right of the tick mark the labels should
be drawn
yoff = 1 ; sets how far below the x-axis the labels should be drawn
cgtext, julday(1+xoff,1,years), min(data)-yoff, strtrim(years,1)

This draws exactly the labels I want (2003-2012), and has the added
benefit of letting me scoot the labels over a bit to the right so that
they are centered under the year interval, rather than centered at the
January 1 tick mark. But it introduces the problem of needing to set
the values for xoff, which will depend on the size of the window, and
yoff, which will depend on the range of the daya (in my example, the
data ranges from -10 to 10, so a yoff = 1 works, but if the data range
was from -1 to 1 or was from -1000 to 1000 then it would not work so
well). The xoff problem can be worked around by explicitly setting the
window size, but the yoff problem is data-dependent.

Is there a better way of doing this that does not depend on the data range?

Thanks in advance!
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: really dumb widget question
Next Topic: Unable to allocate memory

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

Current Time: Wed Oct 08 15:42:33 PDT 2025

Total time taken to generate the page: 0.00424 seconds