# How to redraw a subplot instead of overlaying, GR

**URL:** <https://discourse.julialang.org/t/how-to-redraw-a-subplot-instead-of-overlaying-gr/18473>\
**Category:** Visualization\
**Tags:** plotting\
**Created:** [December 9, 2018, 12:44am UTC](https://discourse.julialang.org/t/how-to-redraw-a-subplot-instead-of-overlaying-gr/18473 "2018-12-09T00:44:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Donut\_Meepo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/donut_meepo/32/9085_2.png) [@Donut\_Meepo](https://discourse.julialang.org/u/Donut_Meepo)\
**Post date:** [December 9, 2018, 12:44am UTC](https://discourse.julialang.org/t/how-to-redraw-a-subplot-instead-of-overlaying-gr/18473/1 "2018-12-09T00:44:09Z")

</div>

Hi,

I am trying to fill the subplots of a layout using GR backend

```julia
layout = @layout [grid(1,2); grid(1,2); grid(1,1)];
plot(layout=layout)
#draw at position2
plot!(1:10, rand(10), subplot=2)
#want to redraw instead of overlay
plot!(1:10, rand(10), subplot=2, clf=true)
#try couple times
plot!(1:10, rand(10), subplot=2, clf=true)

```

what should I do to overwrite the single subplot instead of overlaying. Thanks a lot!

 ![image](https://global.discourse-cdn.com/julialang/original/3X/8/f/8fb54b8ac3ae778e00b3c5049e50903838571155.png)

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [December 10, 2018, 6:53am UTC](https://discourse.julialang.org/t/how-to-redraw-a-subplot-instead-of-overlaying-gr/18473/2 "2018-12-10T06:53:41Z")

</div>

You cannot do that with Plots.

---

<div class="post-metadata">

**Author:** ![Donut\_Meepo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/donut_meepo/32/9085_2.png) [@Donut\_Meepo](https://discourse.julialang.org/u/Donut_Meepo)\
**Post date:** [December 12, 2018, 1:26am UTC](https://discourse.julialang.org/t/how-to-redraw-a-subplot-instead-of-overlaying-gr/18473/3 "2018-12-12T01:26:39Z")

</div>

If I have already plotted 3 subplots and the 4th one I did something wrong, I have to redo everything? Or are there any better way? Thank you for helping

---

<div class="post-metadata">

**Author:** ![kobied](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kobied/32/16432_2.png) [@kobied](https://discourse.julialang.org/u/kobied)\
**Post date:** [January 16, 2020, 4:55pm UTC](https://discourse.julialang.org/t/how-to-redraw-a-subplot-instead-of-overlaying-gr/18473/4 "2020-01-16T16:55:39Z")

</div>

hello, you can update the subplot data as follow:

```julia
using Plots
gr()
layout = @layout [grid(1,2); grid(1,2); grid(1,1)]
p = plot(layout = layout)

plot!(p,1:10,rand(10),subplot=2)

# first we take the second subplot from the subplot array with in 'p', cause this is the subplot 
# we want to change, you can take an other subplot you want
a = p.subplots[2]

# then we take from the series_list array the first cell cause we have only one line with in the 
# plot, if we had more then one, you need to know which line to take according to the order
# you plotted them.
# then we over write the 'y' values. you can over write the 'x' value by using ':x' instead of ':y'
a.series_list[1][:y] = rand(10)

# finally we redraw the plot 
display(p)

```
