By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,853 Members | 1,012 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,853 IT Pros & Developers. It's quick & easy.

plotting data against a time axis

P: n/a
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.

--
208. If he was a freed man, he shall pay one-third of a mina.
-- 1780 BC, Hammurabi, Code of Law
--
Asperger Syndroom - een persoonlijke benadering:
http://people.nl.linux.org/~gerrit/
Kom in verzet tegen dit kabinet:
http://www.sp.nl/

Jul 18 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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.

-- ================================================== ============ <
wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
================================================== ============ <
Bestiaria Home Page: http://www.beastie.dm.net/ <
Home Page: http://www.dm.net/~wulfraed/ <


Jul 18 '05 #2

P: n/a
Gerrit Holl <ge****@nl.linux.org> writes:
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? gnuplot


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
Jul 18 '05 #3

P: n/a
"Dennis Lee Bieber" <wl*****@ix.netcom.com> wrote in message
news:a6************@beastie.ix.netcom.com...
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.)
Jul 18 '05 #4

P: n/a
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 <G>
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.

-- ================================================== ============ <
wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
================================================== ============ <
Bestiaria Home Page: http://www.beastie.dm.net/ <
Home Page: http://www.dm.net/~wulfraed/ <


Jul 18 '05 #5

P: n/a
Alexander Schmolck wrote:
Gerrit Holl <ge****@nl.linux.org> writes:
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?

gnuplot


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.

--
275. If any one hire a ferryboat, he shall pay three gerahs in money
per day.
-- 1780 BC, Hammurabi, Code of Law
--
Asperger Syndroom - een persoonlijke benadering:
http://people.nl.linux.org/~gerrit/
Kom in verzet tegen dit kabinet:
http://www.sp.nl/

Jul 18 '05 #6

P: n/a
Gerrit Holl <ge****@nl.linux.org> writes:
Alexander Schmolck wrote:
Gerrit Holl <ge****@nl.linux.org> writes:
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?

gnuplot


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.


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
Jul 18 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.