Skip to content

Fix autoscaling with twinx and vspans: consider axis with one pair of finite limits ONLY #8513

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

Merged
merged 1 commit into from
Apr 24, 2017

Conversation

ibnIrshad
Copy link

PR Summary

Fixes #6284. The problem was that autoscaling was ignoring all axis limits when any of them were infinite. However we should handle this on a case by case basis: If only the x-limits are infinite, we can still use the y-limits, and vice versa. This makes autoscaling work properly with vspans (which only have infinite y-limits).

In order to reproduce the issue (and verify it is fixed), try this:

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.axvspan(1,2)

bx = ax.twinx()
bx.plot([0,.5], [1,2])
plt.show()

If fixed, you should see that the vspan does not disappear.

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant
  • n/a New features are documented, with examples if plot related
  • n/a Documentation is sphinx and numpydoc compliant
  • n/a Added an entry to doc/users/whats_new.rst if major new feature
  • n/a Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@ibnIrshad ibnIrshad changed the title Fix autoscaling with twinx: consider axis with one pair of finite limits (and one infinite) Fix autoscaling with twinx and vspans: consider axis with one pair of finite limits ONLY Apr 20, 2017
@phobson
Copy link
Member

phobson commented Apr 20, 2017

@ibnIrshad thanks for the PR and detailed description. This looks good to me. The CI failure from Travis was due to a test that is known to sporadically fail. I've restarted that build.

@ibnIrshad ibnIrshad changed the title Fix autoscaling with twinx and vspans: consider axis with one pair of finite limits ONLY [MRG+1] Fix autoscaling with twinx and vspans: consider axis with one pair of finite limits ONLY Apr 20, 2017
Copy link
Member

@dstansby dstansby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot 👍

@dstansby dstansby merged commit 6eb9119 into matplotlib:master Apr 24, 2017
@dstansby dstansby changed the title [MRG+1] Fix autoscaling with twinx and vspans: consider axis with one pair of finite limits ONLY Fix autoscaling with twinx and vspans: consider axis with one pair of finite limits ONLY Apr 24, 2017
dstansby added a commit that referenced this pull request May 1, 2017
Fix autoscaling with twinx and vspans: consider axis with one pair of finite limits ONLY
@dstansby
Copy link
Member

dstansby commented May 1, 2017

Backported to v2.0.x via. bad3406

@dstansby dstansby added this to the 2.0.1 (next bug fix release) milestone May 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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