Skip to content

twinx() does not update margins to contain axis labels [BUG] #3210

@adannenberg

Description

@adannenberg

It is also the case that issue #1276 no longer appears to be solved...

When I run

using Plots
x=1:20
y1=rand(length(x))
y2 = sin.(x)
plot(x,y1,label = "My y1 label", legend = :topleft, ylabel = "the lh y-axis",grid=:off)
plot!(twinx(),y2, label = "my y2 label", legend=:topright, ylabel = "the rh y-axis", grid=:off, xlabel="numbers", color=:red, box=:on)

I get a plot with no label on the right hand y-axis. I'm not sure if it's off the plot to the right or missing (less likely).

It's also the case that a graph such as the one above cannot be included as a subplot with layout. If I change the code above:

using Plots
x=1:20
y1=rand(length(x))
y2 = sin.(x)
p=plot(x,y1,label = "My y1 label", legend = :topleft, ylabel = "the lh y-axis",grid=:off)
plot!(p,twinx(),y2, label = "my y2 label", legend=:topright, ylabel = "the rh y-axis", grid=:off, xlabel="numbers", color=:red, box=:on)

then I get an error:
LoadError: Cannot convert Plots.Subplot{Plots.GRBackend} to series data for plotting

This is true in both Atom+Juno and Pluto. Not sure about different backends (although I know the rh y-axis problem is there with Plotly as well as Gr).

### 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

### Versions

Plots.jl version:
Backend  version (`]st -m`):Status `~/.julia/environments/v1.5/Manifest.toml`
 91a5bcdd] Plots v1.10.0
 Output of `versioninfo()`:Julia Version 1.5.3
Commit 788b2c77c1 (2020-11-09 13:37 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i9-9900 CPU @ 3.10GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-9.0.1 (ORCJIT, skylake)
Environment:
  JULIA_NUM_THREADS = 8

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions