# Double yaxis using plotlyjs() as backend

**URL:** <https://discourse.julialang.org/t/double-yaxis-using-plotlyjs-as-backend/123978>\
**Category:** Visualization\
**Tags:** plots, plotlyjs\
**Created:** [December 19, 2024, 5:08am UTC](https://discourse.julialang.org/t/double-yaxis-using-plotlyjs-as-backend/123978 "2024-12-19T05:08:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stephen](https://avatars.discourse-cdn.com/v4/letter/s/96bed5/32.png) [@Stephen](https://discourse.julialang.org/u/Stephen)\
**Post date:** [December 19, 2024, 5:08am UTC](https://discourse.julialang.org/t/double-yaxis-using-plotlyjs-as-backend/123978/1 "2024-12-19T05:08:38Z")

</div>

Hello, there, I want plot `δGDP` and `δM2` vs `Year` on left yaxis, whereas `δGDP/δM2` vs `Year` on the right side  
Here is my code: anyon can help me with `plot!`? Thanks!

```julia
using Plots
plotlyjs()

begin
    p = plot(
    Year, [δM2, δGDP],
             
    title = "δM2 & δGDP",

    label = ["δM2" "δGDP"],

    fg_legend = :transparent,

    legend_position = (0.1, 0.95),

    ylims = (.0, 250000.0),

    tickfontsize = 11,
        
    legend_font_pointsize = 13,

    size = (800, 600)
    )
    plot!(
        p, Year, δGDP / δM2, yaxis = "y2" # need be fixed 
        label = "δGDP / δM2", 
    )
end

```

| Year | δGDP | δM2 | δGDP/δM2 |
| --- | --- | --- | --- |
| 2000 | 9715.700000000012 | 14849.419999999984 | 0.6542814466827676 |
| 2001 | 50374.90000000014 | 20400.98000000001 | 0.19495496947299085 |
| 2002 | 60970.19999999995 | 30358.440000000002 | 0.21665099384097747 |
| 2003 | 135670.0 | 35979.869999999995 | 0.6918279499817624 |
| 2004 | 27051.800000000047 | 31575.98000000001 | 0.1350516484515501 |
| 2005 | 67234.09999999998 | 45237.34 | 0.4208849626215843 |
| 2006 | 87245.19999999995 | 49537.77999999997 | 0.6391172780705213 |
| 2007 | 85640.80000000005 | 57823.390000000014 | 0.6109839961533676 |
| 2008 | 57536.90000000002 | 71765.29999999999 | 0.36464557700577177 |
| 2009 | 45295.09999999998 | 135057.92000000004 | 0.2763525824154297 |
| 2010 | 50599.90000000002 | 115627.27000000002 | 0.415264428354147 |
| 2011 | 54383.19999999995 | 125739.10999999999 | 0.41082315564628 |
| 2012 | 50639.79999999999 | 122557.90000000002 | 0.41319082653994543 |
| 2013 | 75820.90000000002 | 132376.17999999993 | 0.6030017231710963 |
| 2014 | 63601.59999999998 | 121849.83000000007 | 0.5500570929331806 |
| 2015 | 29273.100000000035 | 163903.29919881 | 0.21674478623689766 |
| 2016 | 49152.29999999999 | 157788.55861205002 | 0.6849034282585037 |
| 2017 | 50653.79999999999 | 140168.64686992997 | 0.876008826186081 |
| 2018 | 32119.600000000006 | 136508.9053192099 | 0.6483859389742541 |
| 2019 | 25478.699999999983 | 159744.6000000001 | 0.5632227712770023 |
| 2020 | 24418.20000000001 | 200307.07000000007 | 0.7733156658954055 |
| 2021 | 15704.600000000006 | 196103.66999999993 | 0.43648295560823336 |
| 2022 | 10854.299999999988 | 281421.2799999998 | 0.3575381343705404 |
| 2023 | 10583.0 | 258392.49000000022 | 0.5187495894805051 |

---

<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 19, 2024, 7:03pm UTC](https://discourse.julialang.org/t/double-yaxis-using-plotlyjs-as-backend/123978/2 "2024-12-19T19:03:09Z")

</div>

> [@Stephen](#):
>
> ```julia
> plot!(p, Year, δGDP / δM2, yaxis = "y2" # need be fixed 
> label = "δGDP / δM2")
> 
> ```

Use `twinx()` for multiple y-axes:

```julia
plot!(twinx(), Year, δGDP ./ δM2, yaxis="y2", label="δGDP / δM2")

```

---

<div class="post-metadata">

**Author:** ![Stephen](https://avatars.discourse-cdn.com/v4/letter/s/96bed5/32.png) [@Stephen](https://discourse.julialang.org/u/Stephen)\
**Post date:** [December 20, 2024, 1:46am UTC](https://discourse.julialang.org/t/double-yaxis-using-plotlyjs-as-backend/123978/3 "2024-12-20T01:46:50Z")

</div>

I tried `twinx()`, but seems like `plotlyjs()` backend does not support `twinx()`, this syntax is in `gr()` backend

---

<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 20, 2024, 5:30am UTC](https://discourse.julialang.org/t/double-yaxis-using-plotlyjs-as-backend/123978/4 "2024-12-20T05:30:38Z")

</div>

Sorry, twinx and twiny seem to only work for the gr, pyplot and pgfplotsx backbends.
