Thanks to visit codestin.com
Credit goes to github.com

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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2272,7 +2272,14 @@ def handle_single_axis(scale, autoscaleon, shared_axes, interval,
# ignore non-finite data limits if good limits exist
finite_dl = [d for d in dl if np.isfinite(d).all()]
if len(finite_dl):
# if finite limits exist for atleast one axis (and the other is infinite), restore the
# finite limits
x_finite = [d for d in dl if (np.isfinite(d.intervalx).all() and (d not in finite_dl))]
y_finite = [d for d in dl if (np.isfinite(d.intervaly).all() and (d not in finite_dl))]

dl = finite_dl
dl.extend(x_finite)
dl.extend(y_finite)

bb = mtransforms.BboxBase.union(dl)
x0, x1 = getattr(bb, interval)
Expand Down
15 changes: 15 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5134,3 +5134,18 @@ def test_minorticks_on(xscale, yscale):
ax.set_xscale(xscale)
ax.set_yscale(yscale)
ax.minorticks_on()


def test_twinx_knows_limits():
fig, ax = plt.subplots()

ax.axvspan(1, 2)
xtwin = ax.twinx()
xtwin.plot([0, 0.5], [1, 2])
# control axis
fig2, ax2 = plt.subplots()

ax2.axvspan(1, 2)
ax2.plot([0, 0.5], [1, 2])

assert((xtwin.viewLim.intervalx == ax2.viewLim.intervalx).all())