# How to share same legend for different plots?

**URL:** <https://discourse.julialang.org/t/how-to-share-same-legend-for-different-plots/91012>\
**Category:** General Usage\
**Tags:** plotting, plots\
**Created:** [November 29, 2022, 9:06pm UTC](https://discourse.julialang.org/t/how-to-share-same-legend-for-different-plots/91012 "2022-11-29T21:06:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rongcuid](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rongcuid/32/42911_2.png) [@rongcuid](https://discourse.julialang.org/u/rongcuid)\
**Post date:** [November 29, 2022, 9:06pm UTC](https://discourse.julialang.org/t/how-to-share-same-legend-for-different-plots/91012/1 "2022-11-29T21:06:31Z")

</div>

I have multiple `plot!()` statements used in a loop. I would like multiple plots to share the same legend, given a label, but Plots generate separate, identical legends for each plot command.

For instance, as a minimal example:

```julia
plot([1],[2]; label="A")
plot!([3],[4]; label="A")

```

I would like both of them to share the same legend, style, etc… Is it possible?

---

<div class="post-metadata">

**Author:** ![rongcuid](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rongcuid/32/42911_2.png) [@rongcuid](https://discourse.julialang.org/u/rongcuid)\
**Post date:** [November 29, 2022, 9:38pm UTC](https://discourse.julialang.org/t/how-to-share-same-legend-for-different-plots/91012/2 "2022-11-29T21:38:31Z")

</div>

Alternatively, I would like to know how to manually add legends.

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [November 30, 2022, 9:14am UTC](https://discourse.julialang.org/t/how-to-share-same-legend-for-different-plots/91012/3 "2022-11-30T09:14:06Z")

</div>

I think manually editing legends is tricky in Plots and might require dropping deep into internals.

Could you clarify what the issue is with your first example? For me it creates a plot with just one legend and one label (A), so I’m not sure what you mean by “share the same legend”?

---

<div class="post-metadata">

**Author:** ![rongcuid](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rongcuid/32/42911_2.png) [@rongcuid](https://discourse.julialang.org/u/rongcuid)\
**Post date:** [November 30, 2022, 2:01pm UTC](https://discourse.julialang.org/t/how-to-share-same-legend-for-different-plots/91012/4 "2022-11-30T14:01:12Z")

</div>

It creates two legends, both of which show the label A. I want one legend with label A.

This arises when I wanted to annotate a plot using some arrows. Multiple arrows share the same category, so they should share the same legend. I have to use multiple `plot!` command because otherwise only the last line segment has an arrow on it. In addition, arrows are not continuous.

---

<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:** [November 30, 2022, 2:51pm UTC](https://discourse.julialang.org/t/how-to-share-same-legend-for-different-plots/91012/5 "2022-11-30T14:51:13Z")

</div>

> [@rongcuid](#):
>
> I would like both of them to share the same legend, style, etc… Is it possible?

After the first plot that displays the series legend, use for the subsequent plots:

```julia
plot!([3],[4]; label=false)

```

---

<div class="post-metadata">

**Author:** ![rongcuid](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rongcuid/32/42911_2.png) [@rongcuid](https://discourse.julialang.org/u/rongcuid)\
**Post date:** [November 30, 2022, 2:52pm UTC](https://discourse.julialang.org/t/how-to-share-same-legend-for-different-plots/91012/6 "2022-11-30T14:52:45Z")

</div>

OK, I will try that.
