# Get a legend with twinx()

**URL:** <https://discourse.julialang.org/t/get-a-legend-with-twinx/63672>\
**Category:** Visualization\
**Tags:** plot\
**Created:** [June 28, 2021, 4:30am UTC](https://discourse.julialang.org/t/get-a-legend-with-twinx/63672 "2021-06-28T04:30:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paolo\_Jara](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paolo_jara/32/25685_2.png) [@Paolo\_Jara](https://discourse.julialang.org/u/Paolo_Jara)\
**Post date:** [June 28, 2021, 4:30am UTC](https://discourse.julialang.org/t/get-a-legend-with-twinx/63672/1 "2021-06-28T04:30:16Z")

</div>

Hi, I’m using the twinx () command, is there a way to have both labels in the same legend?

```plaintext
using Plots
x12=randn(10)
y12=1000*randn(10)
plot(x12, label="x12")
plot!(twinx(), y12, c=:red, legend=:bottomleft, label="y12")

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/d/a/da40a3a8ed90fb8f4873e8a860cfeb484c9fe586.png)

---

<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:** [June 28, 2021, 8:39am UTC](https://discourse.julialang.org/t/get-a-legend-with-twinx/63672/2 "2021-06-28T08:39:50Z")

</div>

A possible workaround:

```julia
using Measures, Plots; gr()

x12=randn(10)
y12=1000*randn(10)
lcx =:blue; lwx=2
lcy =:red; lwy=3
plot([x12[1]], lc=lcy, lw=lwy, label="y12", right_margin=15mm)
plot!(x12, label="x12", lc=lcx, lw=lwx, legend=:topleft)
plot!(twinx(), y12, lc=lcy, lw=lwy, label="")

```

![Plots_gr_twinx_single_legend](https://global.discourse-cdn.com/julialang/original/3X/f/5/f5c5a1b3429ea61f3b776114545a277663605b4a.png)
