From: C M <cmp...@gm...> - 2011-01-27 07:04:09
|
> 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') #comment in #ax.bar(x, times) ax.yaxis_date() fig.autofmt_xdate() plt.show() [1]http://stackoverflow.com/questions/4790265/plot-time-of-day-vs-date-in-matplotlib |