Skip to content

ax.twinx().plot() will reset the x_limits if only an axvspan was used on ax #6284

Closed
@Redoubts

Description

@Redoubts

Create a figure and axis, and add a vspan to that axis. If you twinx it, and apply a plot to the twin, the x_limits can adjust, potentially making the vspan not visible.

Minimal code sample:

fig, ax = plt.subplots(figsize=(12, 10))
ax.axvspan(1,2)
fig.canvas.draw()

before_bx_plot

bx = ax.twinx()
bx.plot([0,.5], [1,2])
fig.canvas.draw()

after_bx_plot

Note how the x-axis labels shifted away from the range (1,2).
I expected:
expected

  • Matplotlib version, Python version and Platform (Windows, OSX, Linux ...)
    Matplotlib 1.5.1 on OS X 10.11 with Python 2.7.10
  • System python, pip install -U matplotlib (with SIP disabled)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Difficulty: Mediumhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issues

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions