# How to clear plots (values are getting overlaid)

**URL:** https://discourse.julialang.org/t/how-to-clear-plots-values-are-getting-overlaid/14796
**Category:** General Usage
**Tags:** plotting
**Created:** [September 11, 2018, 2:55am UTC](https://discourse.julialang.org/t/how-to-clear-plots-values-are-getting-overlaid/14796 "2018-09-11T02:55:19Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Nakul\_Tiruviluamala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nakul_tiruviluamala/32/11228_2.png) [@Nakul\_Tiruviluamala](https://discourse.julialang.org/u/Nakul_Tiruviluamala)
#### Post date: [September 11, 2018, 2:55am UTC](https://discourse.julialang.org/t/how-to-clear-plots-values-are-getting-overlaid/14796/1 "2018-09-11T02:55:19Z")

</div>

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.

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

```

Thanks,  
Nakul

 ![11%20PM](https://global.discourse-cdn.com/julialang/original/3X/f/d/fd539aeb5d26c25ee4657da5521e1c606a0461d2.jpeg)

---

<div class="post-metadata">

### Author: ![slowbrain](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/slowbrain/32/2224_2.png) [@slowbrain](https://discourse.julialang.org/u/slowbrain)
#### Post date: [September 11, 2018, 7:26am UTC](https://discourse.julialang.org/t/how-to-clear-plots-values-are-getting-overlaid/14796/2 "2018-09-11T07:26:01Z")

</div>

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

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

PyPlot.clf()

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

```

---

<div class="post-metadata">

### Author: ![Nakul\_Tiruviluamala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nakul_tiruviluamala/32/11228_2.png) [@Nakul\_Tiruviluamala](https://discourse.julialang.org/u/Nakul_Tiruviluamala)
#### Post date: [September 12, 2018, 1:19pm UTC](https://discourse.julialang.org/t/how-to-clear-plots-values-are-getting-overlaid/14796/3 "2018-09-12T13:19:34Z")

</div>

Thank you, that did it!
