C M, on 2011-01-27 02:03,  wrote:
> > 3) I am getting just hammered with the following error *a lot* in date
> > plotting lately:
> >
> > ValueError: ordinal must be >= 1
> 
> 
> OK, I made up a small runnable sample to show this with bar().  (Using
> code that someone else wrote[1]).  This code runs when using
> plot_date(), but if you comment that out and comment in the ax.bar()
> line, it will give this ValueError.
> 
> 
> import matplotlib.pyplot as plt
> import matplotlib as mpl
> import numpy as np
> import datetime as dt
> 
> # Make a series of events 1 day apart
> x = mpl.dates.drange(dt.datetime(2009,10,1),
>                      dt.datetime(2010,1,15),
>                      dt.timedelta(days=1))
> # Vary the datetimes so that they occur at random times
> # Remember, 1.0 is equivalent to 1 day in this case...
> x += np.random.random(x.size)
> 
> # We can extract the time by using a modulo 1, and adding an arbitrary base 
> date
> times = x % 1 + int(x[0]) # (The int is so the y-axis starts at midnight...)
> 
> # I'm just plotting points here, but you could just as easily use a bar.
> fig = plt.figure()
> ax = fig.add_subplot(111)
> 
> #comment out:
> ax.plot_date(x, times, 'ro')
> 

Hi C. M.,

The reason you were getting that error is because unless you
specify otherwise, ax.bar will make the bottom of the bars at 0 -
which isn't an allowed date, hence the error. Change your bar
line to this (I also added align='center', but you can remove it
if you want):

> #comment in
bot = times.min().round()
ax.bar(x, times-bot, bottom=bot, align='center')
> 
> ax.yaxis_date()
> fig.autofmt_xdate()
> 
> plt.show()

best,
-- 
Paul Ivanov
314 address only used for lists,  off-list direct email at:
http://pirsquared.org | GPG/PGP key id: 0x0F3E28F7 

Attachment: signature.asc
Description: Digital signature

------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires 
February 28th, so secure your free ArcSight Logger TODAY! 
http://p.sf.net/sfu/arcsight-sfd2d
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to