Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
2 tasks done
Redoubts opened this issue Apr 9, 2016 · 3 comments · Fixed by #8513
Closed
2 tasks done

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

Redoubts opened this issue Apr 9, 2016 · 3 comments · Fixed by #8513
Labels
Difficulty: Medium https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues
Milestone

Comments

@Redoubts
Copy link

Redoubts commented Apr 9, 2016

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)
@tacaswell tacaswell added this to the 2.0.1 (next bug fix release) milestone Apr 11, 2016
@tacaswell tacaswell added the Difficulty: Medium https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues label Apr 11, 2016
@tacaswell
Copy link
Member

the autoscaling is apparently not twin axis aware enough.

@patniharshit
Copy link
Contributor

What is the issue here?

@ibnIrshad
Copy link

I think we've tracked down the problem. autoscale_view apparently ignores ALL axis limits when atleast one of the limits is infinite (in this case, the y-limits of a vspan are infinite). We have a PR which fixes this by taking into account the case when either y-limits or x-limits are infinite, but the other is finite. PR coming shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty: Medium https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues
Projects
None yet
4 participants