# How to plot a "global" legend when using subplots?

**URL:** <https://discourse.julialang.org/t/how-to-plot-a-global-legend-when-using-subplots/123531>\
**Category:** Visualization\
**Tags:** plots, drive-by-asker\
**Created:** [December 6, 2024, 10:54am UTC](https://discourse.julialang.org/t/how-to-plot-a-global-legend-when-using-subplots/123531 "2024-12-06T10:54:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [December 6, 2024, 10:54am UTC](https://discourse.julialang.org/t/how-to-plot-a-global-legend-when-using-subplots/123531/1 "2024-12-06T10:54:36Z")

</div>

Take this example:

```julia
using Plots
pla = plot(x->x^2, title="Plot A", legend=nothing);plot!(x->x^3)
plb = plot(x->x^(1/2), title="Plot B", legend=nothing);plot!(x->x^(1/3))
plot(pla,plb,plb,pla,layout=(2,2),plot_title="Two plots", labels=["Serie1" "Serie2"],legend = :outerbottom)

```

Producing:

 ![myplot](https://global.discourse-cdn.com/julialang/original/3X/c/e/ce74913a1faf2a08d23b4d63f5dac7100ddfc372.png)

Is there a way to provide a single global legend, a bit like `plot_title` ?

---

<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:** [December 7, 2024, 1:16am UTC](https://discourse.julialang.org/t/how-to-plot-a-global-legend-when-using-subplots/123531/3 "2024-12-07T01:16:01Z")

</div>

Probably not. But could you clarify what you want it to look like?

---

<div class="post-metadata">

**Author:** ![arnold-c](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/arnold-c/32/222741_2.png) [@arnold-c](https://discourse.julialang.org/u/arnold-c)\
**Post date:** [December 7, 2024, 4:18am UTC](https://discourse.julialang.org/t/how-to-plot-a-global-legend-when-using-subplots/123531/4 "2024-12-07T04:18:50Z")

</div>

If you’re willing to use Makie then this can be done with `GridLayout()` and a `Legend()` function call (though you could just use regular `Axes()`).

> **[Creating complex layouts | Makie](https://docs.makie.org/stable/tutorials/layout-tutorial)**
>
> Create impressive data visualizations with Makie, the plotting ecosystem for the Julia language. Build aesthetic plots with beautiful customizable themes, control every last detail of publication quality vector graphics, assemble complex layouts and...

Apologies if you know this and are intentionally Plots.jl for some other reason

---

<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:** [December 7, 2024, 6:51am UTC](https://discourse.julialang.org/t/how-to-plot-a-global-legend-when-using-subplots/123531/5 "2024-12-07T06:51:13Z")

</div>

In Plots.jl there are two ways to do this: (i) [using insets](https://discourse.julialang.org/t/subplots-with-one-common-legend/60020/3), (ii) [using layouts](https://discourse.julialang.org/t/subplots-in-plots-jl-with-separate-legend/1968/10).
