basic understanding of plotting dates

Maybe this will get you going:

import pylab as p
import datetime as d
from matplotlib.dates import DateFormatter
t = [ d.datetime (2007,9,1,12), d.datetime(2007,9,2,12), d.datetime(2007,9,3,12) ]

t = p.date2num(t)
p.plot_date( t, [10,20,30] )
p.xticks(t)
y = DateFormatter(‘%Y-%m-%d’)
p.gca().xaxis.set_major_formatter(y)
p.draw()

Mark

···

From: “C M” <cmpython@…287…>
Subject: [Matplotlib-users] basic understanding of plotting dates

x = (2007-09-01 12:00:02, 2007-09-02 12:00:02, 2007-09-03 12:00:02)

y = (10, 20, 30)

Mark, Mark, Brendan, John, thanks for the input. I have a related question that may help to continue to clear things up for me. My goal is to use matplotlib with wxPython, and I’ve been able to embed graphs in wxPython apps fine so far (in this case, directly, not using wxMPL). What I wanted to know is whether it is necessary to use pylab or not. I am a little unclear what the purpose of pylab is in distinction to matplotlib itself. I gather that pylab is a way to sort of emulate Matlab, but I am unclear as to whether I need to be using pylab in my apps or not. I am not doing scientific plots, just fairly simple graphs, though I may throw some regression lines and r values on there at some point.

I really just want to keep things as simple as possible, and if I don’t need to use pylab, I’d rather not. Any insight would be helpful. Thank you.
Che M

···

On 9/4/07, Mark Bakker <markbak@…287…> wrote:

Maybe this will get you going:

import pylab as p
import datetime as d
from matplotlib.dates import DateFormatter
t = [ d.datetime (2007,9,1,12), d.datetime(2007,9,2,12), d.datetime(2007,9,3,12) ]

t = p.date2num(t)
p.plot_date( t, [10,20,30] )
p.xticks(t)
y = DateFormatter(‘%Y-%m-%d’)
p.gca().xaxis.set_major_formatter(y)
p.draw()

Mark

From: “C M” <cmpython@…287…>
Subject: [Matplotlib-users] basic understanding of plotting dates

x = (2007-09-01 12:00:02, 2007-09-02 12:00:02, 2007-09-03 12:00:02)

y = (10, 20, 30)

I realize that the clearer question (and one which ties into my original thread) is: do I need pylab to do plot_date()?

···

On 9/4/07, C M < cmpython@…287…> wrote:

Mark, Mark, Brendan, John, thanks for the input. I have a related question that may help to continue to clear things up for me. My goal is to use matplotlib with wxPython, and I’ve been able to embed graphs in wxPython apps fine so far (in this case, directly, not using wxMPL). What I wanted to know is whether it is necessary to use pylab or not. I am a little unclear what the purpose of pylab is in distinction to matplotlib itself. I gather that pylab is a way to sort of emulate Matlab, but I am unclear as to whether I need to be using pylab in my apps or not. I am not doing scientific plots, just fairly simple graphs, though I may throw some regression lines and r values on there at some point.

I really just want to keep things as simple as possible, and if I don’t need to use pylab, I’d rather not. Any insight would be helpful. Thank you.
Che M

On 9/4/07, Mark Bakker <markbak@…287…> wrote:

Maybe this will get you going:

import pylab as p
import datetime as d
from matplotlib.dates import DateFormatter
t = [ d.datetime (2007,9,1,12), d.datetime(2007,9,2,12), d.datetime(2007,9,3,12) ]

t = p.date2num(t)
p.plot_date( t, [10,20,30] )
p.xticks(t)
y = DateFormatter(‘%Y-%m-%d’)
p.gca().xaxis.set_major_formatter(y)
p.draw()

Mark

From: “C M” <cmpython@…287…>
Subject: [Matplotlib-users] basic understanding of plotting dates

x = (2007-09-01 12:00:02, 2007-09-02 12:00:02, 2007-09-03 12:00:02)

y = (10, 20, 30)

C M wrote:

Mark, Mark, Brendan, John, thanks for the input. I have a related question that may help to continue to clear things up for me. My goal is to use matplotlib with wxPython, and I've been able to embed graphs in wxPython apps fine so far (in this case, directly, not using wxMPL). What I wanted to know is whether it is necessary to use pylab or not. I am a little unclear what the purpose of pylab is in distinction to matplotlib itself. I gather that pylab is a way to sort of emulate Matlab, but I am unclear as to whether I need to be using pylab in my apps or not. I am not doing scientific plots, just fairly simple graphs, though I may throw some regression lines and r values on there at some point.

I really just want to keep things as simple as possible, and if I don't need to use pylab, I'd rather not. Any insight would be helpful. Thank you.
Che M

No, you do not need to use pylab. It provides an API that is concise, comfortable, and responsive, especially for interactive use. Even in scripts that are mostly written in OO fashion, use of a few pylab functions (e.g., figure, subplot, show) can simplify the code. This does not apply if you are embedding mpl in wx, however; none of the examples/embedding_in_*.py demos import pylab.

In addition to its role as an alternative interface to mpl, pylab imports most of numpy and some additional functions, providing a somewhat matlab-like environment. This can be handy for interactive work.

There is a range of opinion regarding pylab, but I think the center of the range is: don't use pylab when mpl is embedded; use it very sparingly for normal programming; and for interactive use, if it makes you more productive, use it as much as you want.

Eric

C M wrote:

I realize that the clearer question (and one which ties into my original thread) is: do I need pylab to do plot_date()?

No, plot_date is available as an axes method. Most pylab plotting commands are thin wrappers for axes methods.

Eric

Thanks for your help in clearing this up and the uses of pylab.

So basically I need to use plot_date but in a figure embedded in a wxPython app.

Still not sure how this should be written. To make it simple, this plot() command
works in my app already:

x = [1,2,3]
y = [10,20,30]
self.subplot.plot(x, y)

So, my question is, how would this be modified for a wx app (that is, no pylab

allowed) and use plot_date()? Assume my dates are as given below.

dates (x axis):
09-01-07 12:00:02

09-02-07 12:00:04

09-03-07 12:00:06

values (y axis):
10
20
30

The examples that Bill and Mark gave above in the list showed how to do
this using pylab, but I just need the simplest example and one which does

not use pylab.

Thanks,
Che

···

On 9/4/07, Eric Firing <efiring@…202…> wrote:

C M wrote:

I realize that the clearer question (and one which ties into my original
thread) is: do I need pylab to do plot_date()?

No, plot_date is available as an axes method. Most pylab plotting

commands are thin wrappers for axes methods.

Hey Che -

If you include your graphs in a wxPython app, you shouldn’t use pylab.
Pylab is a wrapper to (quickly) generate graphs, and is very useful,
especially in interactive mode, as it saves a lot of typing and is much
easier to understand (indeed, a lot like matlab plotting). But for
inclusion in apps you need to use matplotlib, so you are on the right
track. This has been discussed several times on the list, but it may
not be so easy to find. Maybe we should put this on the FAQ page (or
maybe it is already there!),

Mark

···

On 9/4/07, C M <cmpython@…287…> wrote:

Mark, Mark, Brendan, John, thanks for the input. I have a related question that may help to continue to clear things up for me. My goal is to use matplotlib with wxPython, and I’ve been able to embed graphs in wxPython apps fine so far (in this case, directly, not using wxMPL). What I wanted to know is whether it is necessary to use pylab or not. I am a little unclear what the purpose of pylab is in distinction to matplotlib itself. I gather that pylab is a way to sort of emulate Matlab, but I am unclear as to whether I need to be using pylab in my apps or not. I am not doing scientific plots, just fairly simple graphs, though I may throw some regression lines and r values on there at some point.

I really just want to keep things as simple as possible, and if I don’t need to use pylab, I’d rather not. Any insight would be helpful. Thank you.
Che M

On 9/4/07, Mark Bakker <markbak@…287…> wrote:

Maybe this will get you going:

import pylab as p
import datetime as d
from matplotlib.dates import DateFormatter
t = [ d.datetime (2007,9,1,12), d.datetime(2007,9,2,12), d.datetime(2007,9,3,12) ]

t = p.date2num(t)
p.plot_date( t, [10,20,30] )
p.xticks(t)
y = DateFormatter(‘%Y-%m-%d’)
p.gca().xaxis.set_major_formatter(y)
p.draw()

Mark

From: “C M” <cmpython@…287…>
Subject: [Matplotlib-users] basic understanding of plotting dates

x = (2007-09-01 12:00:02, 2007-09-02 12:00:02, 2007-09-03 12:00:02)

y = (10, 20, 30)

C M wrote:
[...]

So basically I need to use plot_date but in a figure embedded in a wxPython app.
Still not sure how this should be written. To make it simple, this plot() command
works in my app already:

x = [1,2,3]
y = [10,20,30]
self.subplot.plot(x, y)

I don't understand--where did "self" come from? If we assume that self.subplot is in fact an axes instance, then you can use self.subplot.plot_date(...), where the arguments would be the same as if you were using pylab.plot_date(...).

All this might be clarified if you look at the code for pylab.plot and pylab.plot_date.

I may be missing something; I was not paying attention to earlier parts of this thread, I haven't done much with dates and have never used plot_date myself, and I have no experience with embedding.

Maybe it would also help for you to look at dates.py (one of the mpl modules)?

Eric

···

So, my question is, how would this be modified for a wx app (that is, no pylab
allowed) and use plot_date()? Assume my dates are as given below.

dates (x axis): 09-01-07 12:00:02
09-02-07 12:00:04
09-03-07 12:00:06

values (y axis):
10
20
30

The examples that Bill and Mark gave above in the list showed how to do
this using pylab, but I just need the simplest example and one which does
not use pylab.

Thanks,
Che

x = [1,2,3]
y = [10,20,30]
self.subplot.plot(x, y)

I don’t understand–where did “self” come from?

Sorry–“self” here refers to an instance of a wxPanel class in my wxPython app.
It is the parent window for the mpl subplot which is meant to be a child of it.
The subplot is itself a child of a Figure, so the creation is like this:

self.figure = Figure(None, dpi)
self.subplot = self.figure.add_subplot(111)

If we assume that self.subplot is in fact an axes instance, then you can use
self.subplot.plot_date(…), where the arguments would be the same as if
you were using pylab.plot_date(…).

Is it? How is Figure() related to axes?

Maybe it would also help for you to look at dates.py (one of the mpl
modules)?

I will try; so far, when I try to adapt the examples given in this thread to an
wx embedded app it is not working…

Thanks,
Che

C M wrote:

     > x = [1,2,3]
     > y = [10,20,30]
     > self.subplot.plot(x, y)

    I don't understand--where did "self" come from?

Sorry--"self" here refers to an instance of a wxPanel class in my wxPython app.
It is the parent window for the mpl subplot which is meant to be a child of it.
The subplot is itself a child of a Figure, so the creation is like this:

self.figure = Figure(None, dpi)
self.subplot = self.figure.add_subplot(111)

add_subplot makes an Axes instance and puts it in the Figure instance; self.subplot is this Axes instance, as I had guessed. So, you can apply any Axes method to it.

Eric