How to clear plots (values are getting overlaid)

Hello,
I am struggling with the action of clearing a plot in Julia. Every time I modify the contents of the variable that is to be plotted, it gets overlaid instead of redrawn. My solution for this is to restart my IDE (vscode) every time I want a new plot to be drawn that doesn’t have an overlay of the old values. Is there a simple solution to preventing this from happening? I’ve attached a graph with my function drawn, as well as my plot function (+40 in this example) to illustrate the overlaid nature of my graphs.

plot(y + 40)
xlabel("time")
ylabel("points")
title("Data with Linear Trend")
grid("on")
gcf()

Thanks,
Nakul

1 Like

try to run PyPlot.clf() before declaring new plot:

plot(y)
title("First plot")
gcf()

PyPlot.clf()

plot(y + 40)
title("Second plot")
gcf()
2 Likes

Thank you, that did it!