# Plotting dates on the Y axis?

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?

Thanks!

Regards,
Ken

Kenneth Miller wrote:

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 sure what you mean, have you just tried it with plot or plot_dates?

What problems are you experiencing?

cheers,

Chris

···

--
Simplistix - Content Management, Zope & Python Consulting
- http://www.simplistix.co.uk

Not a problem -- with recent versions of mpl, you can simply pass a
sequence of date objects directly. Use Axes.invert_yaxis to change
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 [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()

···

On Fri, Mar 21, 2008 at 11:27 AM, Kenneth Miller <xkenneth@...287...> 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?

Kenneth Miller wrote:

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 sure what you mean, have you just tried it with plot or plot_dates?

A common type of graph in my work is to see the value (from 0 to something) represented on the x axis, and instead of the y representing a value, it represents time. The closer the Y value gets to the x-axis, the closer it is to the current time, and the further away the further back in time. When i pass plot_dates timestamps for the y axis, and integers for the x axis it simply displays the y-axis as floats.

Regards,
Kenneth Miller

···

On Mar 21, 2008, at 11:56 AM, Chris Withers wrote:

What problems are you experiencing?

cheers,

Chris

--
Simplistix - Content Management, Zope & Python Consulting
- http://www.simplistix.co.uk

Kenneth Miller wrote:

back in time. When i pass plot_dates timestamps for the y axis, and integers for the x axis it simply displays the y-axis as floats.

did you try:

plot_dates(x,dates,ydate=True)

?

Chris

···

--
Simplistix - Content Management, Zope & Python Consulting
- http://www.simplistix.co.uk