I'm writing a little app in wxPython which has a matplotlib figure (using the wxagg backend) panel. I'd like to add the ability for the user to export X,Y data of what is currently plotted in the figure to a text file. Is there a non-invasive way to do this? I've searched quite a bit and can't seem to find anything, though I feel like it is incredibly simple and right in front of my face.
I could definitely get the data and store it somewhere when it is plotted, and use that - but that would be fairly invasive, into the lower levels of my code. It would be so much easier, and universal, if I could do something as easy as:
x = FigurePanel.axes.GetXData()
y = FigurePanel.axes.GetYData()
Hopefully that makes some sense :)
Thanks so much! Any help is greatly appreciated!
edit: to clarify, what I'd like to know how to do is get the X,Y data. Writing to the text file after that is trivial ;)
Artistinstance (or sequence of artists, in the case ofplot) that contains the data, styling information, etc. Many artists haveget_dataandset_datamethods (e.g. you can dox, y = line.get_data()). For some, the method may be called something else (e.g.scatterreturns a collection where the equivalent method isget_offsets) A few artists (ContourSetsfor example) don't contain references to the original input data, but this is quite rare. Basically, you want to hold on to the output of plotting functions. - Joe Kington