# Change labels in existing plot (Plots package)

**URL:** <https://discourse.julialang.org/t/change-labels-in-existing-plot-plots-package/60738>\
**Category:** Visualization\
**Tags:** question, plotting\
**Created:** [May 7, 2021, 6:11pm UTC](https://discourse.julialang.org/t/change-labels-in-existing-plot-plots-package/60738 "2021-05-07T18:11:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![liviomaya](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/liviomaya/32/24871_2.png) [@liviomaya](https://discourse.julialang.org/u/liviomaya)\
**Post date:** [May 7, 2021, 6:11pm UTC](https://discourse.julialang.org/t/change-labels-in-existing-plot-plots-package/60738/1 "2021-05-07T18:11:25Z")

</div>

I have a pre-existing figure with multiple curves and an existing label vector. I need to change the labels - probably using the _plot!_ command - but I am not able to do it. I don’t think this is not a row vector label issue.

I am using Plots package and the GR backend (although I found the same issue using PyPlot). Julia version 1.5.3.

Minimal example:

> using Plots  
> gr()  
> fig = plot(1:5, rand(5,2), label=[“A” “B”])  
> plot!(fig, label = [“C” “D”] )

The last command fails to change labels to C and D. I also tried using _labels_ instead of _label_, no success.

My apologies if this is a trivial question!

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [May 7, 2021, 7:40pm UTC](https://discourse.julialang.org/t/change-labels-in-existing-plot-plots-package/60738/2 "2021-05-07T19:40:29Z")

</div>

I think you will need to dig into the plot object `fig`. In an interactive environment like the REPL you can use `fig.<TAB>` and then keep going down until you find where the actual strings are stored inside and change them.

Or just use the correct labels to start with 😉

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [May 8, 2021, 2:21pm UTC](https://discourse.julialang.org/t/change-labels-in-existing-plot-plots-package/60738/3 "2021-05-08T14:21:59Z")

</div>

@dpsanders, that is nice to know.

`Plots.jl` does not seem to listen to changes made to the plot attributes and any plot update seems to require displaying the whole shebang. So it might be pointless to try partial plot updates.

This can be tested in a plot with thousands of points:

```julia
using Plots; gr()

fig = plot(1:2_000, rand(2_000,2), label=["A" "B"])
fig.series_list[1][:label] = "C"
fig.series_list[2][:label] = "D"
display(fig)

```

[SmoothLivePlot.jl](https://github.com/williamjsdavis/SmoothLivePlot.jl) implements this key capability by using [Observables.jl](https://github.com/JuliaGizmos/Observables.jl) and [WebIO.jl](https://github.com/JuliaGizmos/WebIO.jl) but did not try it to confirm whether it solves the problem above.

---

<div class="post-metadata">

**Author:** ![liviomaya](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/liviomaya/32/24871_2.png) [@liviomaya](https://discourse.julialang.org/u/liviomaya)\
**Post date:** [May 8, 2021, 5:47pm UTC](https://discourse.julialang.org/t/change-labels-in-existing-plot-plots-package/60738/4 "2021-05-08T17:47:06Z")

</div>

Great! Thank you, guys!
