Question on date plotting

Hi,

  Just started playing with matplotlib and it is very impressive.

  I have a question on controlling the x-axis values being plotted. Say I am recording a stock price every hour from say 10am to 3pm on a daily basis. I am trying to plot a multi-day chart such that after the data for 3pm on Day 1 is plotted, the next data should be for 10am on Day 2. Currently matplotlib is automatically adding all the hours from 3pm on Day 1 till 10pm on Day 2 even if I am only supplying the x-axis values that I want to be plotted.

I am doing something like ..

dates = [2008-9-18 10:00, 2008-9-18 11:00, ...., 2008-9-18 15:00, 2008-9-19 10:00, 2008-9-19 11:00,...] # all dates are datetime objs
prices = [1.0, 1.1, ...........]

plot_date(dates, prices)
# plot(dates, prices) -- this doesn't work either

Is it possible to force matplotlib to plot only the data points that I supply instead of it extrapolating the date data.

-srp

Take a look at the date_index_formatter.py example -- this uses daily
data and skips the weekends but it is conceptually similar to your
problem

  http://matplotlib.sourceforge.net/examples/pylab_examples/date_index_formatter.py

The approach is to plot evently spaced indices for the xaxis, and then
use your date vector as a lookup table for formatting the x
locations. The same approach could be used for a date index locator,
to put the ticks where you want them. See the chapter on tick
locating and formatting in the user's guide for background, and let me
know if you get stuck.

···

On Wed, Sep 24, 2008 at 6:05 AM, Saju Pillai <saju.pillai@...287...> wrote:

Hi,

Just started playing with matplotlib and it is very impressive.

I have a question on controlling the x-axis values being plotted.
Say I am recording a stock price every hour from say 10am to 3pm on a
daily basis. I am trying to plot a multi-day chart such that after the
data for 3pm on Day 1 is plotted, the next data should be for 10am on
Day 2. Currently matplotlib is automatically adding all the hours from
3pm on Day 1 till 10pm on Day 2 even if I am only supplying the x-axis
values that I want to be plotted.

Hi,

Just started playing with matplotlib and it is very impressive.

I have a question on controlling the x-axis values being plotted.
Say I am recording a stock price every hour from say 10am to 3pm on a
daily basis. I am trying to plot a multi-day chart such that after the
data for 3pm on Day 1 is plotted, the next data should be for 10am on
Day 2. Currently matplotlib is automatically adding all the hours from
3pm on Day 1 till 10pm on Day 2 even if I am only supplying the x-axis
values that I want to be plotted.

Take a look at the date_index_formatter.py example -- this uses daily
data and skips the weekends but it is conceptually similar to your
problem

http://matplotlib.sourceforge.net/examples/pylab_examples/date_index_formatter.py

This worked perfectly. Thanks.

-srp

···

On 24-Sep-08, at 6:15 PM, John Hunter wrote:

On Wed, Sep 24, 2008 at 6:05 AM, Saju Pillai <saju.pillai@...287...> > wrote:

The approach is to plot evently spaced indices for the xaxis, and then
use your date vector as a lookup table for formatting the x
locations. The same approach could be used for a date index locator,
to put the ticks where you want them. See the chapter on tick
locating and formatting in the user's guide for background, and let me
know if you get stuck.