On Fri, Mar 21, 2008 at 11:27 AM, Kenneth Miller <[EMAIL PROTECTED]> wrote:
> All,
>
>       Is it possible to plot dates on the Y-axis? I'd like to have
>  dates on the y axis descending or ascending versus my values on the x
>  - axis. Is it possible to do this or simply switch the axis?

Not a problem -- with recent versions of mpl, you can simply pass a
sequence of date objects directly.  Use Axes.invert_yaxis to change
the order from ascending to descending.  Here is an example loading
some data from a CSV file and plotting floats on the x axis and dates
on the y axis

In [7]: import matplotlib.mlab as mlab

In [8]: r = mlab.csv2rec('aapl.csv')

In [9]: r.sort()

In [10]: r[-5:]
Out[10]:
recarray([ (datetime.date(2008, 2, 11), 128.00999999999999,
129.97999999999999, 127.2, 129.44999999999999, 42886900,
129.44999999999999),
       (datetime.date(2008, 2, 12), 130.69999999999999, 131.0, 123.62,
124.86, 43749900, 124.86),
       (datetime.date(2008, 2, 13), 126.68000000000001, 129.78,
125.63, 129.40000000000001, 34542300, 129.40000000000001),
       (datetime.date(2008, 2, 14), 129.40000000000001,
130.80000000000001, 127.01000000000001, 127.45999999999999, 34074900,
127.45999999999999),
       (datetime.date(2008, 2, 15), 126.27, 127.08, 124.06, 124.63,
32163400, 124.63)],
      dtype=[('date', '|O4'), ('open', '<f8'), ('high', '<f8'),
('low', '<f8'), ('close', '<f8'), ('volume', '<i4'), ('adj_close',
'<f8')])

In [11]: fig = figure()

In [12]: ax = fig.add_subplot(111)

In [13]: ax.plot(r.close, r.date, 'o')
Out[13]: [<matplotlib.lines.Line2D instance at 0x237fc10>]

In [14]: draw()


In [15]: ax.invert_yaxis()

In [16]: draw()

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to