extracting displayed data from axes

How can I extract from a figure or axes the data that it currently
displays?

I had hoped that something like

from pylab import *
plot([1,3,2])
data = getp(gca(), 'data')
xdata = getp(gca(), 'xdata')
ydata = getp(gca(), 'ydata')

would do the trick, as suggested by the brief mention of these
properties at

  http://matplotlib.sourceforge.net/matplotlib.pyplot.html#-plot

but all I get is the exception

Traceback (most recent call last):
  File "bug.py", line 3, in <module>
    data = getp(gca(), 'data')
  File "/usr/lib/python2.5/site-packages/matplotlib/artist.py", line 629, in getp
    func = getattr(o, 'get_' + name)
AttributeError: Subplot instance has no attribute 'get_data'

in python-matplotlib-0.91.1. Thanks for any suggestions!

Markus

P.S.: It seems that the link

  http://matplotlib.sourceforge.net/matplotlib.pyplot.html#-getp

on

  http://matplotlib.sourceforge.net/

is broken.

···

--
Markus Kuhn, Computer Laboratory, University of Cambridge
http://www.cl.cam.ac.uk/~mgk25/ || CB3 0FD, Great Britain

Hello Markus,

How can I extract from a figure or axes the data that it currently
displays?

I had hoped that something like

from pylab import *
plot([1,3,2])
data = getp(gca(), 'data')
xdata = getp(gca(), 'xdata')
ydata = getp(gca(), 'ydata')

An axes instance does not provide data-properties. They belong to the lines,
that were already plotted in that axes. But the axes instance provides a list
of all plotted lines (gca().lines).

xdata = getp(gca().lines[0], 'xdata')
# or the OOP-way
# last line instance of the list of lines:
line = gca().lines[-1]
ydata = line.get_ydata()

regards Matthias

P.S.: It seems that the link

  http://matplotlib.sourceforge.net/matplotlib.pyplot.html#-getp

on

  http://matplotlib.sourceforge.net/

is broken.

(+1)

···

On Saturday 10 May 2008 22:01:22 Markus Kuhn wrote: