# Updating a plot

**URL:** <https://discourse.julialang.org/t/updating-a-plot/35457>\
**Category:** New to Julia\
**Tags:** plotting, visualization, plots\
**Created:** [March 3, 2020, 11:51am UTC](https://discourse.julialang.org/t/updating-a-plot/35457 "2020-03-03T11:51:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pjgorski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pjgorski/32/4802_2.png) [@pjgorski](https://discourse.julialang.org/u/pjgorski)\
**Post date:** [March 3, 2020, 11:51am UTC](https://discourse.julialang.org/t/updating-a-plot/35457/1 "2020-03-03T11:51:12Z")

</div>

How to update an already created plot?

Let’s say we have a plotting function returning a handle like this one:  
`h=plot(x, y, seriestype:scatter)`  
And, afterwards, we decided to change the scatter points to a solid line.  
I tried to do the following:

```julia
h.series_list[1].plotattributes[:seriestype]=:line
h

```

But it gives following error:

```julia
Error showing value of type Plots.Plot{Plots.PyPlotBackend}:
ERROR: BoundsError: attempt to access 0-element Array{Any,1} at index [1]

```

Any hints?

---

<div class="post-metadata">

**Author:** ![dmolina](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dmolina/32/5246_2.png) [@dmolina](https://discourse.julialang.org/u/dmolina)\
**Post date:** [March 3, 2020, 12:46pm UTC](https://discourse.julialang.org/t/updating-a-plot/35457/2 "2020-03-03T12:46:07Z")

</div>

First, it is better to give a complete and running example:

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …

Also, you should indicate the plotting libraries and/or backend to help you.

---

<div class="post-metadata">

**Author:** ![pjgorski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pjgorski/32/4802_2.png) [@pjgorski](https://discourse.julialang.org/u/pjgorski)\
**Post date:** [March 3, 2020, 1:29pm UTC](https://discourse.julialang.org/t/updating-a-plot/35457/3 "2020-03-03T13:29:21Z")

</div>

Working example:

```julia
using Plots
#plots backend doesn't matter. I can use any. Question is general how to do it. 
h=plot(rand(5), rand(5), seriestype=:scatter)
h.series_list[1].plotattributes[:seriestype]=:line
h

```

With `PyPlot` it produces mentioned above error. With `GR` it creates empty plot.  
I suppose the reason is, there are some other parameters (e.g. line thickness) that I should change to update the curves. But maybe there is a simple solution?

---

<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:** [March 3, 2020, 4:49pm UTC](https://discourse.julialang.org/t/updating-a-plot/35457/4 "2020-03-03T16:49:47Z")

</div>

You can’t really change an existing plot with Plots. Just plot it again. This is one of the things that Makie does better.
