plotting data against a time axis

G

Gerrit Holl

Hi,

I have a dictionairy containing DateTime objects as keys and integers as
values. What would be the easiest way to create a simple plot of these,
with a number axis versus a time axis? What library is the most
suitable for this? 'plot' on parnassus yields 18 hits, but since I have
zero experience, I don't know where to start. What makes it difficult
is that I have a time axis instead of a simple integer x-axis. Gnuplot
doesn't seem to be able to do this, or does it?

I could, of course, write the data as a .csv, import it in OpenOffice
and create a chart with OpenOffice, but I don't really see how to get
OOffice to use the first column with iso dates as time axis, and I
want to be able to do this automatically.

yours,
Gerrit Holl.
 
A

Alexander Schmolck

Gerrit Holl said:
Hi,

I have a dictionairy containing DateTime objects as keys and integers as
values. What would be the easiest way to create a simple plot of these,
with a number axis versus a time axis? What library is the most
suitable for this? 'plot' on parnassus yields 18 hits, but since I have
zero experience, I don't know where to start. What makes it difficult
is that I have a time axis instead of a simple integer x-axis. Gnuplot
doesn't seem to be able to do this, or does it?

G N U P L O T
Version 3.8j patchlevel 0
last modified Wed Nov 27 20:49:08 GMT 2002

Terminal type set to 'x11'
gnuplot> help time
Ambiguous request 'time'; possible matches:
time/date
time_specifiers
timefmt
timestamp

Not what you want?

'as
 
D

Dennis Lee Bieber

Gerrit Holl fed this fish to the penguins on Saturday 15 November 2003
14:19 pm:
I have a dictionairy containing DateTime objects as keys and integers
as values. What would be the easiest way to create a simple plot of
these, with a number axis versus a time axis? What library is the most
suitable for this? 'plot' on parnassus yields 18 hits, but since I
have zero experience, I don't know where to start. What makes it
difficult is that I have a time axis instead of a simple integer
x-axis. Gnuplot doesn't seem to be able to do this, or does it?

Maybe I need to check the specs of the DateTime module, but most
systems that work in dates usually store them internally in a linear
format. Ignoring the /time/ aspect, a date could be stored in pseudo
human readable format as an 8-digit integer -- yyyymmdd -- which sorts
linearly, regardless of how it is formatted for display.

IOW, time /is/ a integer (or, if using whole dates, a floating point
with time of day as a fraction) counted from some epoch.

At worst, take the earliest (time wise) date in your data as an epoch,
and rebuild your dictionary using the delta from the epoch as the new
key/index.

--
 
P

Paul McGuire

Dennis Lee Bieber said:
Maybe I need to check the specs of the DateTime module, but most
systems that work in dates usually store them internally in a linear
format. Ignoring the /time/ aspect, a date could be stored in pseudo
human readable format as an 8-digit integer -- yyyymmdd -- which sorts
linearly, regardless of how it is formatted for display.

Ooops, not really. This trick will correctly *order* dates for sorting, but
they wont ascend linearly. I think that you'll find big non-linear gaps
between the last days of a month and the first day of the next:
20031029
20031030 (delta is 1)
20031031 (delta is 1)
20031101 (delta is 70)
....
20031230
20031231 (delta is 1)
20040101 (delta is 8870!)

At worst, take the earliest (time wise) date in your data as an epoch,
and rebuild your dictionary using the delta from the epoch as the new
key/index.
For the OP to get a nice scatter-plot, with linear time as the x-axis
variable, this is what he/she will have to do. Simplest is to contrive an
epoch with a starting day number (01/01/2000?), plus the time represented as
a fraction of a whole day, (so that noon on day 17 will be represented as
17.5, 6pm as 17.75, etc.)
 
D

Dennis Lee Bieber

Paul McGuire fed this fish to the penguins on Saturday 15 November 2003
18:58 pm:

Ooops, not really. This trick will correctly *order* dates for
sorting, but

Okay, okay... I did say "readable", whereas ddmmyyyy is all over the
map said:
For the OP to get a nice scatter-plot, with linear time as the x-axis
variable, this is what he/she will have to do. Simplest is to
contrive an epoch with a starting day number (01/01/2000?), plus the
time represented as a fraction of a whole day, (so that noon on day 17
will be represented as 17.5, 6pm as 17.75, etc.)
Or go to the astronomical format used for Julian date -- where noon is
x.0 and midnight is x.5 (avoids having a 'day' change occur in the
middle of observations -- unless, of course, you are observing sunspots
<G>).

My main interest was that I'd expect almost any time/date module to
have /some/ sort of linear basis available for plotting purposes.

--
 
G

Gerrit Holl

Alexander said:
G N U P L O T
Version 3.8j patchlevel 0
last modified Wed Nov 27 20:49:08 GMT 2002

Terminal type set to 'x11'
gnuplot> help time
Ambiguous request 'time'; possible matches:
time/date
time_specifiers
timefmt
timestamp

Not what you want?

Hm, maybe it is, actually :). It seems my estimate was incorrect; to be
fair, I assumed Gnuplot was used solely for plotting functions, not data.
Maybe it is wise to invest some time in learning Gnuplot, I may be happy
with it later as well.

Thank you all (John, Alexander, Dennis, Paul) for the responses!

Gerrit.
 
A

Alexander Schmolck

Gerrit Holl said:
Hm, maybe it is, actually :). It seems my estimate was incorrect; to be
fair, I assumed Gnuplot was used solely for plotting functions, not data.
Maybe it is wise to invest some time in learning Gnuplot, I may be happy
with it later as well.

I think it is well worthwhile.

I used to regard gnuplot as a waste of time (because of its poor output
quality and a number of bizzarre warts), and because I have matlab available
for plotting (also from within python), which has very comprehensive
functionality.

However I came to appreciate that gnuplot is actually quite useful for quick
and dirty plots, in particular from somewhat messy input files, because
gnuplot helpfully just ignores stuff it can't regard as datapoints. Also its
text based interface, although not perfect, is also far more effective than
most GUI crap, once you got a slight hang of it and saving the plot results in
a file of gnuplot commands which is easy to modify and/or to reuse. Finally
gnuplot has the advantage of being quite ubiquitous and will presumably stay
around for another couple of years.

As a quick example, this will generate a 3D point plot from a text file (that
amongst other things) contains point coordinates in 3 columns (2,3,4).

gnuplot> splot 'locs.xyz' using 2:3:4 with points

Than's to unique prefixes, you'd actually just have to type something like:

gnuplot> sp 'locs.xyz' us 2:3:4 w p

A final word of advice: I'd strongly recommend you track down version 3.8j (or
latter, if already available) -- it has extremely useful enhancements such as
zooming with mouse and decent 3d plots.

'as
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top