1

I would like to have a double y-axis in one of my subplots; however, it seems like I am missing something about twinx() and link = :x, but I couldn't figure out what..

Plotting double y-axis using twinx() works fine in a standard plotting frame. However, it creates the following problem when I try to link the x-axes. What am I missing here?

using Plots

x = [3, 5, 7, 9];
y = [10, 20, 30 , 40];
z = [-10, -20, -30, -40];

a = plot(1:10, color = :black, legend = false)

b = plot(x, y, color = :green, legend = false)
b = scatter!(twinx(), x, z, color = :orange, legend = false)

plot(a, b, layout = (2, 1), link= :x)

Output:

enter image description here

Thank you very much!

  • 1
    You can try to have a look at this post that uses the pyplot backend [link](https://discourse.julialang.org/t/linking-axes/8633/2) – Matteo Vilucchio Jun 03 '22 at 14:36
  • I have asked the same question on Julia discourse -please find the solution here: https://discourse.julialang.org/t/double-y-axes-in-a-sub-plot/82186 – Vautrin Balzac Jun 03 '22 at 14:54

0 Answers0