Clear memory after using plot!(...)

Hello,

is there a simple command for Julia to clear memory after using plot!(…) without having to constantly restart VS Code?

Best regards …

Why would you want that? Can you explain your issue?

… test environment … I create new plots via the console and no longer need the previous plots.
For this reason, I want to clear the memory so that I can create new plots again with plots!(…)

Do you want to delete the series inside the plot canvas and keep the decoration (title, axes, axes limits and labels), to be able to replot onto the same canvas ?

You can always create new plots, by either starting another plot with, for example:

plot(rand(10))
plot!(rand(10))
plot(rand(20)) # new plot
plot!(rand(20))

or, which might give you better control, assing the plot to a variable:

p1 = plot(rand(10))
plot!(p1, rand(10)))

p2 = plot(rand(20))
plot!(p2, rand(20)))

If you have a memory issue (which is unlikely, I guess), you can try setting the variables to nothing, so they become-garbage collected at some point:

p1 = nothing

I just want use the console and I want clear the memory for the plots. I don’t want fill new variables.
I have an vector array from numerical simulations.
I just plot some vectors from this array.
Afterwards, I change something in the simulation and I want plot vectors from the new array again.
I just use the console for plot!(…).
It´s for me faster, than write any blocks in the main script.
For this issue I restart VS Code again, again and again.

@rafael.guerra: I want clear all points from the previous plots.

Try this code, as example:

using Plots
p = plot(sin, lims=(-2,2), title="My playing canvas")
plot!(p, cos)

# Clear plots series
foreach(sp -> empty!(sp.series_list), p.subplots)
p

# replot while keeping plot limits and decorations
plot!(p, cos)

hmmm … Is there really no way to reset the memory entry like I would restart VS Code? … like a kill switch ^^
Okay … I will try it.

The julia language is garbage collected(GC). If you close the plot and loose reference to the plot, the language itself de-allocates the memory. If you need to manually trigger memory garbage collection for some reason, you can trigger it by GC.gc() but first you need to re-associate(=) bindings(variables) which reference memory to something like nothing. You usually do not need to manually clear memory due to the GC and memory will be reused if the plot redrawn with something new. If you are asking for plot pane in VS Code it is the julia extensions feature to show you older plots in the same session.

For that use plot() (without the !), and you will start a new plot.

I think they talk about the plotpane:


I also noticed that those actually take up ram, and I dont know how to clear it.

Uhm… are you sure? I have VSCode sections literally running for weeks with currently >100 plots in the pane. It doesn’t seem to make any difference in memory usage.

I am running simulations with different initial data.
I get a solution vector-matrix; after each time-step the programm saves a solution vector in this matrix. I compare some solutions from different time-steps directly with
plot!(solution[1])
plot!(solution[10])

Nothing special … all graphs are included in a plot.

After changing the initial data for a new simulation run, I want also plot the new solutions in a new plot.
But Julia plots the new data in the same plot, which includes the old data.

So I am looking just for a console command like plot!(…), to clear the previous data from the plot (or initial a new plot).

Did you try plot(...) (without ! )?

I cannot compare solution vectors in a same plot just with plot(…).
I get a new plot for each vector.

So just do:

plot(vec1)
plot!(vec2, vec3...)

You can also define your own vector plot function that combines these two calls, like:

function vecplot(vec)
    plot(vec[1])
    plot!(vec[2:end])
end

I did not try this myself, just as idea.

The plot() without the ! creates a new plot, and the plot!() with the ! modifies that previously created plot.

That is, in each new comparison, the first plot is without the !.

Let’s take a look at this example…

Is there a way to clear the counter from ‘Julia Plots (5/5)’ to zero?

Restart VSCode. If you don’t like that, create an issue at: GitHub · Where software is built

My comment: Using advanced features of VSCode creates more problems than it solves.

You are mixing two things. That has nothing to do with the subsequent plots being added to the same plot or no.

Isn’t just:

plot(solution[1]) # no !
plot!(solution[2]) # with !

what you want?

If not, I think you need to explain better what’s your problem.