I am struggling to generate a plot with two y-axes. The left y-ticks show up on the right y-axis. Also, I am uisng rightmargin = 1.5Plots.cm, box = :on
because the label margins are broken.
using Plots
pyplot()
plot(rand(10), leg=false, ylims=(-.1,1), framestyle=:box, rightmargin = 1.5Plots.cm, box = :on)
plot!(twinx(), leg=false, 100*rand(10), ylims=(0,100), ylabel="right")
Using the GR backend works in this simple example, but it breaks in my code. Are there any other ways to fix the axis? Is this a bug that should be reported?
2 Likes
I have the same issue. Still no solution?
Your code seems to work fine for me, Win11, Julia 1.8.5, PyPlot v2.11.1, Plots v1.38.10:
1 Like
It also works for me now.
Version Info
Julia 1.9.0 RC2
Ubuntu 20.04
[91a5bcdd] Plots v1.38.10
[d330b81b] PyPlot v2.11.1
@Woodmouth, what is your version information? I am wondering if you need to upgrade your packages.
Updating the packages worked. Thanks!
Never mind, it was not the package versions but rather that I had set default(framestyle=:box)
which meant that the framestyle of the twinx plot was also set to :box
which apparently breaks it.
A separate issue is that even though the twinx axis does work now, we do loose the line at the top, so it seems as though twinx perhaps overwrites the framestyle somehow, even though that probably shouldn’t be the intended behavior. I would prefer to to have the line at the top of the plot like it should if the framestyle was set to box
.
using Plots
Plots.reset_defaults()
pyplot()
#default(framestyle=:box)
plot(rand(10), leg=false, ylims=(-.1,1), rightmargin = 1.5Plots.cm, box = :on)
plot!(twinx(), leg=false, 100*rand(10), framestyle=:box, ylims=(0,100), ylabel="right")
Just hammer a last nail in the coffin:
plot!(framestyle=:box)
1 Like