I have a wxPython
program which reads from different datasets, performs various types of simple on-the-fly analysis on the data and plots various combinations of the datasets to matplotlib
canvas. I would like to have the opportunity to dump currently plotted data to file for more sophisticated analysis later on.
The question is: are there any methods in matplotlib
that allow access to the data currently plotted in matplotlib.Figure
?
Save as PDF File If you want to export a graph with matplotlib, you will always call . savefig(path) . matplotlib will figure out the file type based on the passed file path .
Use get_xdata() and get_ydata() methods on the line to get xy data. To display the figure, use show() method.
Just call the plot() function and provide your x and y values. Calling the show() function outputs the plot visually.
Jakub is right about modifying the Python script to write out the data directly from the source from which it was sent into the plot; that's the way I'd prefer to do this. But for reference, if you do need to get data out of a plot, I think this should do it
gca().get_lines()[n].get_xydata()
Alternatively you can get the x and y data sets separately:
line = gca().get_lines()[n] xd = line.get_xdata() yd = line.get_ydata()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With