# How to prevent plot! from over-writing earlier saved plot

**URL:** <https://discourse.julialang.org/t/how-to-prevent-plot-from-over-writing-earlier-saved-plot/51072>\
**Category:** Visualization\
**Tags:** plotting\
**Created:** [December 2, 2020, 1:05am UTC](https://discourse.julialang.org/t/how-to-prevent-plot-from-over-writing-earlier-saved-plot/51072 "2020-12-02T01:05:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![CosmoProf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cosmoprof/32/15516_2.png) [@CosmoProf](https://discourse.julialang.org/u/CosmoProf)\
**Post date:** [December 2, 2020, 1:05am UTC](https://discourse.julialang.org/t/how-to-prevent-plot-from-over-writing-earlier-saved-plot/51072/1 "2020-12-02T01:05:46Z")

</div>

Hi, I’ve asked this as part of an earlier question, but no resolution yet.

In my program, I have this contour plot extracted from data after many hours of execution,  
and I have to add new data on top of the contour plot (in the same window, on the same axes). So it was suggested I do this:

```julia
plot!(SavedContourPlot, (NewYdata, NewXdata))

```

and that works… BUT, it over-writes `SavedContourPlot`, which ruins it, since I must use that original contour plot again later with other data, but cannot waste the time to re-calculate it. These commands also don’t help:

```julia
HoldTheOldPlot = SavedContourPlot
NewPlot = plot!(SavedContourPlot, (NewYdata, NewXdata)); display(NewPlot)

```

because now `HoldTheOldPlot `, `NewPlot `, and `SavedContourPlot` ALL get changed in the same way, getting the new data added to the plots.

Is there any way that I can use the `plot!` command in the way shown above, which adds the new data to the old plots in the way that I need it, but ALSO keep an unchanged copy of the old contour plot somehow? Thanks…!

---

<div class="post-metadata">

**Author:** ![aramirezreyes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aramirezreyes/32/42573_2.png) [@aramirezreyes](https://discourse.julialang.org/u/aramirezreyes)\
**Post date:** [December 2, 2020, 3:10am UTC](https://discourse.julialang.org/t/how-to-prevent-plot-from-over-writing-earlier-saved-plot/51072/2 "2020-12-02T03:10:22Z")

</div>

Can you do something like this?

```julia
OldXData,OldYData = CalculateData(a,b,c) #this process takes ages
SavedContourPlot = plot(OldXData,OldYData)
NewContourPlot = plot(OldXData,OldYData) #do twice the plot, this shouldn't recompute the data, you end up with two different objects
plot!(NewContourPlot, (NewYdata, NewXdata)); display(NewContourPlot) #Modify only one of the plot objects

```

Another option is to do what you were trying but using the deepcopy function:

```julia
HoldTheOldPlot = deepcopy(SavedContourPlot)
NewPlot = plot!(SavedContourPlot, (NewYdata, NewXdata)); display(NewPlot)

```

This will work because you are actually copying the plot object and associating it with the binding `HoldTheOldPlot`, whereas in your version, you were only pointing said binding to the same object.

You can read more about the `deepcopy` function by doing `?deepcopy` in the REPL

---

<div class="post-metadata">

**Author:** ![CosmoProf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cosmoprof/32/15516_2.png) [@CosmoProf](https://discourse.julialang.org/u/CosmoProf)\
**Post date:** [December 2, 2020, 3:40am UTC](https://discourse.julialang.org/t/how-to-prevent-plot-from-over-writing-earlier-saved-plot/51072/3 "2020-12-02T03:40:14Z")

</div>

Yes, `deepcopy` works, thank you!

(The first solution wouldn’t have worked, since I need to make copies of the contour plot on the fly, after the source data is already gone.)
