I'm using python with matplotlib to create plots out of data, an I'd like to save this plots on a pdf file (but I could use also a more specific format). I'm using basically this instructions:
plt.plot(data)
figname = ''.join([filename, '_', label, '.pdf'])
plt.savefig(figname)
But what this does is create an image of the plot with the zoom in which it's displayed; I would like to create a copy that shows all points (>10000) that I'm plotting so I would be able to zoom to any level. Which is the correct way to do that?
EDIT: is there a format (such as '.fig' for Matlab) that calls directly the viewer of Matplotlib with the data i saved? Maybe it's possible to create a .py script that saves the points and that i can call to quickly re-display them? I think that this is what is done by the .fig Matlab file.
I don't know of any native Matplotlib file format which includes your data; in fact, I'm not sure the Matploblib objects even have a write function defined.
What I do instead to simulate the Matlab .fig concept is to save the processed data (as a numpy array, or pickled) and run a separate .py script to recreate the Matplotlib plots.
So in steps:
It is a bit clumsy, but it works. If you really want, you could embed the pickled data as a string in your plotting script (Embed pickle (or arbitrary) data in python script). This gives you the benefit of working with a single python script containing both the data as well as the plotting code.
You can check for the existence of your stored processed data file and skip the processing steps if this file exists. So:
if not processed_data.file exists:
my_data = process_raw_data()
else:
my_data = read_data_from_file(processed_data.file)
plot(my_data)
In this way, you can have one script for both creating the graph in the first place, and re-plotting the graph using pre-processed data.
You might want to add a runtime argument for forcing a re-processing of the data in case you change something to the processing script and don't want to manually remove your processed data file.