poly_between and time series data

Hello,

I am trying to fill the space below a curve where my x-axis is indexed by time. The matplotlib api documentation and the examples don't touch on this subject and I haven't had much luck trying a few different variations. Here's what I've tried so far, maybe someone can point out what I'm doing wrong.

import time
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab

time_strings = [ list of times as strings ]
xs = [ date2num(time.strptime(string) for string in time_strings ]
ys = [ list of float values ]

fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot_date(xs, ys)

xv, yv = mlab.poly_below(0, xs, ys)
ax.fill(xv, yv)

When I do this, I get a 'year out of range' error. If I try and fill the area before the call to ax.plot_date, The fill looks like a solid bar about the height of the max y-value.

From, looking at the posts on the mailing list it doesn't seem that I'm doing something terribly wrong, maybe I'm missing something subtle?

Thanks,
   - Shailesh

Shailesh Kochhar wrote:

Hello,

I am trying to fill the space below a curve where my x-axis is indexed by time. The matplotlib api documentation and the examples don't touch on this subject and I haven't had much luck trying a few different variations. Here's what I've tried so far, maybe someone can point out what I'm doing wrong.

import time
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab

time_strings = [ list of times as strings ]
xs = [ date2num(time.strptime(string) for string in time_strings ]
ys = [ list of float values ]

fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot_date(xs, ys)

xv, yv = mlab.poly_below(0, xs, ys)
ax.fill(xv, yv)

When I do this, I get a 'year out of range' error. If I try and fill the area before the call to ax.plot_date, The fill looks like a solid bar about the height of the max y-value.

What is the actual traceback?
Please provide a simple but complete example that shows the problem--that is, flesh out your pseudocode above into a small standalone script that triggers the error.

Eric

···

From, looking at the posts on the mailing list it doesn't seem that I'm doing something terribly wrong, maybe I'm missing something subtle?

Thanks,
   - Shailesh

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

I think there is a bug in poly_below -- try usin poly_between

   xv, yv = mlab.poly_between(xs, ys, 0)

I've fixed the bug in svn r6429, so you can also use svn if you have
access to it.

JDH

···

On Thu, Nov 20, 2008 at 10:09 PM, Eric Firing <efiring@...202...> wrote:

Shailesh Kochhar wrote:

Hello,

I am trying to fill the space below a curve where my x-axis is indexed
by time. The matplotlib api documentation and the examples don't touch
on this subject and I haven't had much luck trying a few different
variations. Here's what I've tried so far, maybe someone can point out
what I'm doing wrong.

import time
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab

time_strings = [ list of times as strings ]
xs = [ date2num(time.strptime(string) for string in time_strings ]
ys = [ list of float values ]

fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot_date(xs, ys)

xv, yv = mlab.poly_below(0, xs, ys)
ax.fill(xv, yv)

John Hunter wrote:

···

On Thu, Nov 20, 2008 at 10:09 PM, Eric Firing <efiring@...202...> wrote:

Shailesh Kochhar wrote:

Hello,

I am trying to fill the space below a curve where my x-axis is indexed
by time. The matplotlib api documentation and the examples don't touch
on this subject and I haven't had much luck trying a few different
variations. Here's what I've tried so far, maybe someone can point out
what I'm doing wrong.

import time
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab

time_strings = [ list of times as strings ]
xs = [ date2num(time.strptime(string) for string in time_strings ]
ys = [ list of float values ]

fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot_date(xs, ys)

xv, yv = mlab.poly_below(0, xs, ys)
ax.fill(xv, yv)

I think there is a bug in poly_below -- try usin poly_between

   xv, yv = mlab.poly_between(xs, ys, 0)

I've fixed the bug in svn r6429, so you can also use svn if you have
access to it.

Thanks, that works like a charm.

   ~sk