Search code examples
pythonplotsaving-data

Saving data from Python program into a 'workspace' so I can plot without having to the run the program again


Using MATLAB, all data and variables tare saved into a workspace. This makes it really easy to access and manipulate the data for simple plotting from the command window without having to run the main program again.

I know this can be done using Spyder, but how would one go about saving the data so I can run a smaller, secondary plotting program in any IDE / Terminal. This program would then access this data so I don't have to run the main program every time a small change is made to the plotting.

Are there benefits to some file formats over others? i.e. Do some file formats compress the data? Do some allow for faster access? Are there options to keep the data in a workspace outside of Spyder?

Most of the data would either be 2D numpy arrays and would be plotted as images, or 1D numpy arrays for line plotting.


Solution

  • You could use Google Colab for this. It allows you to segment Python code so you can run your main program in one segment, then create the plotting code in the following segment. After you run the first segment, all the data is saved at that point so you don't need to rerun it.

    If you're running this code on your local machine, you can just save the numpy arrays into a numpy file like this: https://numpy.org/doc/1.18/reference/generated/numpy.save.html

    Then, when you run your plotting program, you can read in from that numpy file.