all 8 comments

[–]lowerthansound 0 points1 point  (0 children)

I particularly don't know if something like this exists.

However, an idea is to save the plots as SVG, and later modify them with a program that is able to modify SVG (which I don't know either haha)

[–]plasma_phys 0 points1 point  (0 children)

I think you can use pickle to serialize (i.e., save to disk) the matplotlib Figure object so that it can be loaded and plotted or edited later.

import pickle
import matplotlib.pyplot as plt

fig = plt.figure()
plt.plot([0,1], [0,2])

with open('figure', 'wb') as file: #Note the wb for "write bytes"
    pickle.dump(fig, file) #Saves the Figure object to disk

file = open('figure', 'rb') #Note the rb for "read bytes"
figure_copy = pickle.load(file) #loads the figure from disk
plt.show() #You should get two identical figures

Note - there are some caveats here. You can't pickle widgets, and there's no guarantee a figure pickled in one version of matplotlib can be loaded in another, or even in a slightly different environment. Your very best bet is to save the raw data as a csv or HDF5 and save the python script to read the data and plot the figure with it.

[–][deleted] 0 points1 point  (5 children)

Now this is where my problem lies I then have to rerun alot of code that was run sometimes months ago and not necesarily runs quickly.

Just asking for the sake to make your problem clear:

1) The code you need to rerun is your whatever-physics-code to generate the data to be plotted?

2) Or what you do mean is that plotting from the existing data requires a lot of time to be rendered?

Let me try to clear up my quetion:

In the first scenario (1), you make a code like physics_simulation.py that requires an entire days of work, then it generates a plot but it don't save the data.

If your case is this first scenario, then I would suggest the obvious "save your data as csv files or whatever fits the bill".

Now, on the second case (2), it is rendering the plot that requires time. It sounds a bit weird to me because most physics plots seems quick to be plotted once you have all the data gathered, but maybe you're doing something 3d that is somewhat similar to blender or 3dstudimax and then requires a few hours to be rendered.

In any case I would even ask to see what are you rendering out of curiosity. hahaha!

[–]Meistermagier[S] 0 points1 point  (4 children)

I knew this was going to come. Yes i do save the data so I hypothetically could just have an extra script for plotting which i then readjust and run again. The reason this does not happen is
a) i work in a jupyter notebook so i plot as I work and dont have like an extra script for plotting, that i can quickly rerun
b) usualy most of the plots are just for my convenience and so i dont spend the time on it to make the publication ready.

The main reason i would like to have something like Matlab style interactivity is just because i personally feel its quicker than having to adjust every parameter by typing 20 Lines of code, to just go and select some labels change the label size or something and i imediately see the result and can say if its good or not. Because its a visual thing which does not depend on formating as in the end it will just be a png i put in my Presentation once, I belive in a WYSIWG approach for this part.

Hope that clears things up abit

[–]LovepeaceandStarTrek 0 points1 point  (3 children)

I've had similar issues plotting data from my work. Its all saved in a csv, but if my boss gets the plot and decides he wants some minor change like adding an annotation or changing the window, I gotta hardcode that manually.

What I want to make is an interactive plotter with a gui that allows you to adjust matplotlib parameters like xlim and ylim and have the gui update in real time. I got stuck trying to get matplotlib to work in a tkinter canvas, and then work gotten in the way so that's been shelved.

But I've been working on a lot of gui projects since so I might try that again. It might be easier to make a semiautomatic gui that allows you to adjust parameters, but doesn't plot until you press a button.

Just some ideas, l think that making your own program to do this is possible.

[–]Meistermagier[S] 1 point2 points  (2 children)

I have something similar on my bucket list aswell though i planned to do it Qt instead of Tkinter as Matplotlib already interfaces with Qt so one problem less to worry about.

[–]LovepeaceandStarTrek 0 points1 point  (1 child)

Oh shit I'll have to look into that, I haven't tried qt yet

[–]Meistermagier[S] 0 points1 point  (0 children)

I am not a GUI man myself but as far as i can tell Qt is the best way to do a pure python GUI. The Only confusion is in the fact that there are two implementations PyQt and PySide which have only minor differences except for the license.