How to redraw a subplot instead of overlaying, GR


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

layout = @layout [grid(1,2); grid(1,2); grid(1,1)];
#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!

1 Like

You cannot do that with Plots.

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

hello, you can update the subplot data as follow:

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


# 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