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

Skip to content

Commit bad3406

Browse files
committed
Merge pull request #8513 from ibnIrshad/fix6284_squashed
Fix autoscaling with twinx and vspans: consider axis with one pair of finite limits ONLY
1 parent 717bb40 commit bad3406

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2284,7 +2284,14 @@ def handle_single_axis(scale, autoscaleon, shared_axes, interval,
22842284
# ignore non-finite data limits if good limits exist
22852285
finite_dl = [d for d in dl if np.isfinite(d).all()]
22862286
if len(finite_dl):
2287+
# if finite limits exist for atleast one axis (and the other is infinite), restore the
2288+
# finite limits
2289+
x_finite = [d for d in dl if (np.isfinite(d.intervalx).all() and (d not in finite_dl))]
2290+
y_finite = [d for d in dl if (np.isfinite(d.intervaly).all() and (d not in finite_dl))]
2291+
22872292
dl = finite_dl
2293+
dl.extend(x_finite)
2294+
dl.extend(y_finite)
22882295

22892296
bb = mtransforms.BboxBase.union(dl)
22902297
x0, x1 = getattr(bb, interval)

lib/matplotlib/tests/test_axes.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4901,6 +4901,21 @@ def test_minorticks_on():
49014901
ax.minorticks_on()
49024902

49034903

4904+
def test_twinx_knows_limits():
4905+
fig, ax = plt.subplots()
4906+
4907+
ax.axvspan(1, 2)
4908+
xtwin = ax.twinx()
4909+
xtwin.plot([0, 0.5], [1, 2])
4910+
# control axis
4911+
fig2, ax2 = plt.subplots()
4912+
4913+
ax2.axvspan(1, 2)
4914+
ax2.plot([0, 0.5], [1, 2])
4915+
4916+
assert((xtwin.viewLim.intervalx == ax2.viewLim.intervalx).all())
4917+
4918+
49044919
if __name__ == '__main__':
49054920
import nose
49064921
import sys

0 commit comments

Comments
 (0)