JuliaPlots / Plots.jl

Powerful convenience for Julia visualizations and data analysis
https://docs.juliaplots.org
Other
1.83k stars 353 forks source link

[FR] Load and edit old plots #3799

Closed casasgomezuribarri closed 2 years ago

casasgomezuribarri commented 2 years ago

I'm pretty sure this is not possible right now... Please someone correct me if I'm wrong.

It is very annoying to go and check your saved plots from the last session only to realise there is a typo in one of the axis labels, the legend, or the title. It would be great to be able to save the plots in a format that also stores the instructions for creating them, so that they can be retrieved and modified.

I use Julia for data science. A feature like this would allow me, for example, to train several instances of a model saving the coefficient plots for all of them; and then come back later, recover all those plots and superpose them to get an average coefficient plot.

isentropic commented 2 years ago

This is already the case, as far as I know

isentropic commented 2 years ago
p = plot(...)  # old plot
p2 = plot(...) # new plot
display(p) # recover the old one
isentropic commented 2 years ago

And then, you could explicitly plot!(p, ....) to modify it

casasgomezuribarri commented 2 years ago

Thanks for the reply, but maybe I didn't explain myself very well. I want to modify plots that I have already saved as .png files in the past as part of a julia session that is not running anymore (i.e. the variable p from you example doesn't exist anymore).

Example: Can I remove the legend from this old plot? I made it months ago but forgot to specify leg = false. However, to build it again from scratch I would have to evaluate the performance of all those models again, which takes time (and energy because MLJ has been updated since then and the code needs a few changes to work).

Performance Estimates 1

isentropic commented 2 years ago

2 options

  1. serialize your plots object into a file along the image,
  2. Use some graphical editing like gimp
isentropic commented 2 years ago

Better yet, keep the data in a file and keep the script to plot the graph. This is not something Plots should do

BeastyBlacksmith commented 2 years ago

Also check out the hdf5 backend

t-bltg commented 2 years ago

You cannot modify the final png. You have to store the intermediate Plots object. @isentropic is right this is a Serialization job:

Session 1

$ julia
julia> using Plots, Serialization
julia> p = plot([1, 2])
julia> serialize("/tmp/foo", p)

Session 2

$ julia
julia> using Plots, Serialization
julia> p = deserialize("/tmp/foo")
julia> Plots.CURRENT_PLOT.nullableplot = p  # optionally set the current plot
julia> savefig(p, "/tmp/foo.png")

But keep in mind that this reuses your old data. Keep data separate from the plotting script, and rerun the plotting script on new data when your model has produced new data.