First impression from a new user
[Repost, sorry if you get this twice.]
Hi guys,
in my quest for a better gnuplot replacement, I came across matplotlib
yesterday.
I really like it, big thanks to the developers.
It was pretty easy to port over a gnuplot command file. There are
two things that could have been easier still though:
-
My data file consists of a date (in ISO format) and integers. Parsing
the date was a bit of work. I understand that python’s datetime doesn’t
provide any parsing of dates - but maybe matplotlib should have some
functions for that then? FWIW, here is how gnuplot does this (adapted
from http://t16web.lanl.gov/Kawano/gnuplot/datetime-e.html):
set xdata time
set timefmt “%Y-%m-%d”
set format x “%Y-%m”
In my matplotlib script, I’m now doing:
mydate = [int(elem) for elem in vals_line[0].split(’-’)]
datenums.append(date2num(datetime.date(mydate[0], mydate[1], mydate[2])))
[…]
plotline = plot_date(datenums, data)
-
gnuplot has a plot style “steps”
(http://t16web.lanl.gov/Kawano/gnuplot/intro/style-e.html) - I
could only fake that with with extra “dummy” points in matplotlib
as I understand it. It would be nice if matplotlib could do this
for me.
Cheers,
Colin
You can use python's time module to parse dates, see time.strptime and time.strftime.
Jonathan
Marquardt, Colin wrote:
···
[Repost, sorry if you get this twice.]
Hi guys,
in my quest for a better gnuplot replacement, I came across matplotlib
yesterday.
I really like it, big thanks to the developers.
It was pretty easy to port over a gnuplot command file. There are
two things that could have been easier still though:
* My data file consists of a date (in ISO format) and integers. Parsing
the date was a bit of work. I understand that python's datetime doesn't
provide any parsing of dates - but maybe matplotlib should have some
functions for that then? FWIW, here is how gnuplot does this (adapted
from http://t16web.lanl.gov/Kawano/gnuplot/datetime-e.html):
set xdata time
set timefmt "%Y-%m-%d"
set format x "%Y-%m"
In my matplotlib script, I'm now doing:
mydate = [int(elem) for elem in vals_line[0].split('-')]
datenums.append(date2num(datetime.date(mydate[0], mydate[1], mydate[2])))
[...]
plotline = plot_date(datenums, data)
* gnuplot has a plot style "steps"
(http://t16web.lanl.gov/Kawano/gnuplot/intro/style-e.html) - I
could only fake that with with extra "dummy" points in matplotlib
as I understand it. It would be nice if matplotlib could do this
for me.
Cheers,
Colin
--
------------------------------------------------------------------------
I'm part of the Team in Training: please support our efforts for the
Leukemia and Lymphoma Society!
http://www.active.com/donate/tntsvmb/tntsvmbJTaylor
GO TEAM !!!
------------------------------------------------------------------------
Jonathan Taylor Tel: 650.723.9230
Dept. of Statistics Fax: 650.725.8977
Sequoia Hall, 137 www-stat.stanford.edu/~jtaylo
390 Serra Mall
Stanford, CA 94305
Here's a code snippet I found somewhere that demonstrates the use:
def make_datetime(s, fmt='%Y-%m-%d %H:%M'):
'''convert string to datetime'''
ts = time.mktime(time.strptime(s, fmt))
return datetime.fromtimestamp(ts)
Warning, this is very slow, if you need to do a lot of conversions it will take some time.
Bill
Jonathan Taylor wrote:
···
You can use python's time module to parse dates, see time.strptime and time.strftime.
Jonathan
Marquardt, Colin wrote:
[Repost, sorry if you get this twice.]
Hi guys,
in my quest for a better gnuplot replacement, I came across matplotlib
yesterday.
I really like it, big thanks to the developers.
It was pretty easy to port over a gnuplot command file. There are
two things that could have been easier still though:
* My data file consists of a date (in ISO format) and integers. Parsing
the date was a bit of work. I understand that python's datetime doesn't
provide any parsing of dates - but maybe matplotlib should have some
functions for that then? FWIW, here is how gnuplot does this (adapted
from http://t16web.lanl.gov/Kawano/gnuplot/datetime-e.html):
set xdata time
set timefmt "%Y-%m-%d"
set format x "%Y-%m"
In my matplotlib script, I'm now doing:
mydate = [int(elem) for elem in vals_line[0].split('-')]
datenums.append(date2num(datetime.date(mydate[0], mydate[1], mydate[2])))
[...]
plotline = plot_date(datenums, data)
* gnuplot has a plot style "steps"
(http://t16web.lanl.gov/Kawano/gnuplot/intro/style-e.html) - I
could only fake that with with extra "dummy" points in matplotlib
as I understand it. It would be nice if matplotlib could do this
for me.
Cheers,
Colin