Setting the xaxis date ranges

Hi all, I am trying to figure out how I can limit the xaxis date ranges. I tried set_xlim(), but that didn’t work. The graph consists of dates for the xaxis and data for the yaxis. Currently the xaxis is showing the entire year’s worth of months, even though there are no data for some months. This plot is really close to what I want, however, I need to limit the xaxis to a only a few months.

weeks = matplotlib.dates.WeekdayLocator() # every year

months = matplotlib.dates.MonthLocator() # every month

monthsFmt = matplotlib.dates.DateFormatter(’%b’)

fig = pylab.figure()

ax = fig.add_subplot(111)

ax.xaxis.set_major_locator(months)

ax.xaxis.set_major_formatter(monthsFmt)

ax.xaxis.set_minor_locator(weeks)

pylab.bar(x,y)

set_xlim() (or pylab.xlim() ) should work just fine. You should use
the same kind of data as you used for x in your pylab.bar() call.
Personally, I've used datetime objects so the following works:

import datetime
pylab.xlim(datetime.datetime(2010, 03, 01), datetime.datetime(2010, 07, 01))

If this doesn't work for you, I'd need to see what data you're plotting with.

Ryan

···

On Tue, Jun 22, 2010 at 2:52 PM, Fa <fayoeu@...287...> wrote:

Hi all, I am trying to figure out how I can limit the xaxis date ranges. I
tried set_xlim(), but that didn't work. The graph consists of dates for the
xaxis and data for the yaxis. Currently the xaxis is showing the entire
year's worth of months, even though there are no data for some months. This
plot is really close to what I want, however, I need to limit the xaxis to a
only a few months.
weeks = matplotlib.dates.WeekdayLocator() # every year
months = matplotlib.dates.MonthLocator() # every month
monthsFmt = matplotlib.dates.DateFormatter('%b')
fig = pylab.figure()
ax = fig.add_subplot(111)
ax.xaxis.set_major_locator(months)
ax.xaxis.set_major_formatter(monthsFmt)
ax.xaxis.set_minor_locator(weeks)
pylab.bar(x,y)

--
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma