Re: Tick labels and dates [message #41820] |
Wed, 24 November 2004 16:18 |
Mark Hadfield
Messages: 783 Registered: May 1995
|
Senior Member |
|
|
Michael Wallace wrote:
> Now, there's the plotting part of my code. The previous examples showed
> this label_date stuff, but since I'm not using that, how do I go about
> creating the correct labels? If I use JD values for that axis, is there
> some magic option where I can give it the format code?
Use TICKFORMAT ([XYZ]TICKFORMAT for direct graphics commands)
TICKFORMAT
A string, or an array of strings, in which each string represents a
format string or the name of a function to be used to format the tick
mark labels. If an array is provided, each string corresponds to a
level of the axis. (The TICKUNITS property determines the number of
levels for an axis.) If the number of strings stored in this property
is one, GetProperty returns a scalar string, otherwise GetProperty
returns an array of strings.
If the string begins with an open parenthesis, it is treated as a
standard format string. (See Format Codes.)
If the string does not begin with an open parenthesis, it is
interpreted as the name of a callback function to be used to generate
tick mark labels. This function is defined with either three or four
parameters, depending on whether TICKUNITS is specified.
Don't worry about array values, as they're only relevant for multi-level
axes. (There are various problems with multi-level axes that make them
an intriguing toy, IMHO. Also, note that when it says above that the
TICKUNITS property determines the number of levels for an axis it means
the *number of elements* of TICKUNITS determines the number of levels.)
So the following (not tested) should give you a plot with an x-axis with
an interval of one month and with each tick mark labelled in "yyyy-mm"
format:
PLOT, ..., XMINOR=0, XTICKUNITS='month', XTICKINTERVAL=1, $
XTICKFORMAT='(C(CYI4.4,"-",CMOI2.2))'
--
Mark Hadfield "Ka puwaha te tai nei, Hoea tatou"
m.hadfield@niwa.co.nz
National Institute for Water and Atmospheric Research (NIWA)
|
|
|
Re: Tick labels and dates [message #41822 is a reply to message #41820] |
Wed, 24 November 2004 14:23  |
Michael Wallace
Messages: 409 Registered: December 2003
|
Senior Member |
|
|
> I'm not a fan of LABEL_DATE, mainly because it uses a common block, so
> there is endless scope for confusing interactions between apparently
> unrelated graphs. I think that it is much simpler and safer to use the
> C() calendar-format codes directly in your axis's TICKFORMAT string. You
> will need to convert your time data to Julian Days, but how hard is that?
I was trying to figure out how in the world label_date was working.
Common blocks. Ugh. I am no fan of common blocks either and avoid them
like the plague.
Now that I've read through the C() it will do what I need it to do. My
problem was that it wasn't intuitively obvious for me to look up "C()".
Converting seconds since 1970 to a Julian day isn't hard. 1 Jan 1970
00:00:00 is 2440587.5 JD. Just convert the seconds to days and add it
to 2440587.5.
Now, there's the plotting part of my code. The previous examples showed
this label_date stuff, but since I'm not using that, how do I go about
creating the correct labels? If I use JD values for that axis, is there
some magic option where I can give it the format code? Or will I need
to go the ugly route and create the axis with JD, get the labels,
convert them and reset the label values?
-Mike
|
|
|
Re: Tick labels and dates [message #41823 is a reply to message #41822] |
Wed, 24 November 2004 13:34  |
Mark Hadfield
Messages: 783 Registered: May 1995
|
Senior Member |
|
|
Haje Korth wrote:
> Mike,
> you want to look at the examples given for the LABEL_DATE function. It
> assumes that you have time array as Julian day. If you don't (and who does)
> you will have to do your own conversion. I keep my time usually as CDF
> epoch, so I wrote myself a little function that converts CDF epoch first to
> year, month, day, hh, mm, ss with cdf_epoch and then use julday to calculate
> the julian day from these data. Now conversion is pretty much transparent
> without having to worry what Julian day means. LABEL_DATE is pretty flexible
> in the date format and you can easily switch between the formats you like.
> AFAIK, there is no other build-in functionality for time axis.
I'm not a fan of LABEL_DATE, mainly because it uses a common block, so
there is endless scope for confusing interactions between apparently
unrelated graphs. I think that it is much simpler and safer to use the
C() calendar-format codes directly in your axis's TICKFORMAT string. You
will need to convert your time data to Julian Days, but how hard is that?
--
Mark Hadfield "Ka puwaha te tai nei, Hoea tatou"
m.hadfield@niwa.co.nz
National Institute for Water and Atmospheric Research (NIWA)
|
|
|
Re: Tick labels and dates [message #41834 is a reply to message #41823] |
Wed, 24 November 2004 00:58  |
R.Bauer
Messages: 1424 Registered: November 1998
|
Senior Member |
|
|
Michael Wallace wrote:
> I have never been good with figuring how how all the date formatting
> stuff works. I want to label the X axis on a few of my plots with some
> readable date strings. In certain cases, I'd like to display something
> of the form "HH:MI:SS". Other times I'd like to see a day of month or a
> day of year or some other variation.
>
> Anyway, assuming that I have a timestamp in the form of seconds since
> the 1970 epoch, is there some built in way to convert to the time string
> my choosing? Or will I have to role my own conversions? Secondly, how
> do I go about cleanly setting the labels on my IDLgrAxis to the strings?
>
> TIA,
> Mike
Dear Mike
probably this routine from our library could help
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_source/idl _html/dbase/setup_time_axis_dbase.pro.html
This routine is based on julian seconds. This time format was first
introduced by Ray Sterner (JHUAPL)
If you like to have the right minor ticks for the months over a time
period you should have a look into the minor ticks routine. There is an
example implemented.
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_source/idl _html/dbase/rb_axis_minor_dbase.pro.html
pro my_plot
x=dindgen(864)*100
y=sin(x/100)
setup_time_axis, x, $
XRANGE = xrange, $
XSTYLE = xstyle,$
XTITLE = xtitle, $
XTICKS = xticks, $
XMINOR = xminor, $
XTICKV = xtickv, $
XTICKNAME = xtickname, $
TIMEFORMAT = 'HH:MM:SS' , $
TIMESTEP = timestep, $
FORCE_10DAYS=1 ,$
xmtickv=xmtickv
plot,x,y,$
XRANGE = xrange, $
XSTYLE = xstyle, $
XTITLE = xtitle, $
XTICKS = xticks, $
XMINOR = xminor, $
XTICKV = xtickv,$
XTICKNAME = xtickname
end
--
Reimar Bauer
Institut fuer Stratosphaerische Chemie (ICG-I)
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
------------------------------------------------------------ -------
a IDL library at ForschungsZentrum Juelich
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_lib_intro. html
============================================================ =======
|
|
|
Re: Tick labels and dates [message #41838 is a reply to message #41834] |
Tue, 23 November 2004 14:01  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Haje Korth writes:
> you want to look at the examples given for the LABEL_DATE function. It
> assumes that you have time array as Julian day. If you don't (and who does)
> you will have to do your own conversion. I keep my time usually as CDF
> epoch, so I wrote myself a little function that converts CDF epoch first to
> year, month, day, hh, mm, ss with cdf_epoch and then use julday to calculate
> the julian day from these data. Now conversion is pretty much transparent
> without having to worry what Julian day means. LABEL_DATE is pretty flexible
> in the date format and you can easily switch between the formats you like.
> AFAIK, there is no other build-in functionality for time axis.
There are some good time and date functions on the JHUAPL
IDL library site, too. I'm too jet lagged to remember what
they are right now (and too unmotivated to look), but a
search of the one line catalog file should turn them up.
http://fermi.jhuapl.edu/s1r/idl/s1rlib/local_idl.html
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
Re: Tick labels and dates [message #41839 is a reply to message #41838] |
Tue, 23 November 2004 13:41  |
Haje Korth
Messages: 651 Registered: May 1997
|
Senior Member |
|
|
Mike,
you want to look at the examples given for the LABEL_DATE function. It
assumes that you have time array as Julian day. If you don't (and who does)
you will have to do your own conversion. I keep my time usually as CDF
epoch, so I wrote myself a little function that converts CDF epoch first to
year, month, day, hh, mm, ss with cdf_epoch and then use julday to calculate
the julian day from these data. Now conversion is pretty much transparent
without having to worry what Julian day means. LABEL_DATE is pretty flexible
in the date format and you can easily switch between the formats you like.
AFAIK, there is no other build-in functionality for time axis.
Haje
"Michael Wallace" <mwallace.no.spam@no.spam.swri.edu.invalid> wrote in
message news:10q7aj04g0ail9c@corp.supernews.com...
> I have never been good with figuring how how all the date formatting
> stuff works. I want to label the X axis on a few of my plots with some
> readable date strings. In certain cases, I'd like to display something
> of the form "HH:MI:SS". Other times I'd like to see a day of month or a
> day of year or some other variation.
>
> Anyway, assuming that I have a timestamp in the form of seconds since
> the 1970 epoch, is there some built in way to convert to the time string
> my choosing? Or will I have to role my own conversions? Secondly, how
> do I go about cleanly setting the labels on my IDLgrAxis to the strings?
>
> TIA,
> Mike
|
|
|