Plots.jl
Plots.jl copied to clipboard
[BUG] twinx() broken for pgfplots and plotly backends
Backends
This bug occurs on ( insert x
below )
Backend | yes | no | untested |
---|---|---|---|
gr (default) | x | ||
pyplot | x | ||
plotly | x | ||
plotlyjs | x | ||
pgfplotsx | x | ||
inspectdr | x |
Details
I found this issue with pgfplots()
, but I tried to reproduce it with the other backends and had another hiccup, though pgfplots()
was the most egregious. Note I wasn't even able to make an initial plot with insepctdr()
, which I don't really use so I didn't bother trying to figure out what's wrong there. The simple test code is:
using Plots
x = [1,2,3]
y1 = [1,2,3]
y2 = [4,5,6]
plot(x,y1,ylim=(0,6))
plot!(twinx(),x,y2,ylim=(0,6))
this output the following for each backend. The behavior I expected from pgfplots()
(and the other backends) to begin with is the one that gr()
gives: yaxis ticks and labels on the right side. plotly()
and plotlyjs()
don't quite do this, while pgfplots()
does something else entirely.
gr()
pyplot()
plotly()
plotlyjs()
pgfplots()
With inspectdr()
, as soon as I tried to plot anything, it would print some errors and kick me out of the REPL. That should be a separate issue, but for now I'm more concerned with pgfplots()
.
Also as a separate note if someone could help me set the REPL default plot show to pdf instead of svg for pgfplots()
that'd be great. Yes I know I can savefig
as a pdf. But I want to know if it's possible to once you hit plot(...)
on the REPL, to automatically pop up a pdf instead of svg. Thanks!
Versions
Plots.jl version: Plots v1.6.0
Backend version (]st -m
):
GR v0.51.0
PyPlot v2.9.0
PlotlyBase v0.4.1
PlotlyJS v0.14.0
PGFPlots v3.3.2
*InspectDR v0.3.9
Output of versioninfo()
:
Julia Version 1.5.1
Commit 697e782ab8 (2020-08-25 20:08 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-9.0.1 (ORCJIT, haswell)
the pgfplots part is a duplicate of https://github.com/JuliaPlots/Plots.jl/issues/2071. Also note that the pgfplots
backend got deprecated for the pgfplotsx
backend
Thanks for the heads up! I guess I wasn't very thorough finding out if the issue had already been reported. In any case, while not as terrible looking, still a problem using pgfplotsx()
Hi All: I'm also getting this weird lines with Plots.GR()
backend while using twinx()
The error is: QPainterPath::arcTo: Adding arc where a parameter is NaN, results are undefined
. It works just fine with plotly()
and if I save the figure.

Do you have a MWE for that?
I think I figured out where the problem is (vide infra). Here is MWE
using Plots
x = range(0, 100)
y1 = 0.5*x
y2 = -5 * x
plot(x, y1, label=false, color=:red,
linewidth=2,left_margin = 5Plots.mm, right_margin = 15Plots.mm, ylabel="foo")
plot!(twinx(), x, y2, label=false,
color=:black, linewidth=2,left_margin = 5Plots.mm, right_margin = 15Plots.mm, ylabel="bar")
Since I'm doing heavy computation, I start julia with -O3
and --math-mode=fast
which cause gr()
to give this problem, more particularly --math-mode
is causing the problem.
Well --math-mode=fast
is a dangerous thing to do. It would be better to wrap computations where you are okay with using unsafe operation into @fastmath
and avoid setting this globally.
Make sense. Thanks!
Any news on this? I have the same bug when using the plotlyjs backend. Neither twinx() nor ymirror=true are working.
Plots v1.30.0 PlotlyJS v0.18.8 PlotlyBase v0.8.18 Julia Version 1.6.6 Commit b8708f954a (2022-03-28 07:17 UTC) Platform Info: OS: Windows (x86_64-w64-mingw32) CPU: Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz WORD_SIZE: 64 LIBM: libopenlibm LLVM: libLLVM-11.0.1 (ORCJIT, haswell)
An update on this: twinx
and twiny
now work as expected on gr
, pyplot
and pgfplotsx
(see https://github.com/JuliaPlots/Plots.jl/pull/4488).
For plotly(js)
it needs more rework, or the issue is upstream.