Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit26ed35b

Browse files
author
Chris Beaumont
committed
Better axis limits when using shared axes and empty subplots
1 parent89e53aa commit26ed35b

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

‎lib/matplotlib/axes/_base.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1895,6 +1895,11 @@ def autoscale_view(self, tight=None, scalex=True, scaley=True):
18951895
ifscalexandself._autoscaleXon:
18961896
xshared=self._shared_x_axes.get_siblings(self)
18971897
dl= [ax.dataLimforaxinxshared]
1898+
#ignore non-finite data limits if good limits exist
1899+
finite_dl= [dfordindlifnp.isfinite(d).all()]
1900+
iflen(finite_dl):
1901+
dl=finite_dl
1902+
18981903
bb=mtransforms.BboxBase.union(dl)
18991904
x0,x1=bb.intervalx
19001905
xlocator=self.xaxis.get_major_locator()
@@ -1916,6 +1921,11 @@ def autoscale_view(self, tight=None, scalex=True, scaley=True):
19161921
ifscaleyandself._autoscaleYon:
19171922
yshared=self._shared_y_axes.get_siblings(self)
19181923
dl= [ax.dataLimforaxinyshared]
1924+
#ignore non-finite data limits if good limits exist
1925+
finite_dl= [dfordindlifnp.isfinite(d).all()]
1926+
iflen(finite_dl):
1927+
dl=finite_dl
1928+
19191929
bb=mtransforms.BboxBase.union(dl)
19201930
y0,y1=bb.intervaly
19211931
ylocator=self.yaxis.get_major_locator()
@@ -3257,5 +3267,3 @@ def get_shared_x_axes(self):
32573267
defget_shared_y_axes(self):
32583268
'Return a copy of the shared axes Grouper object for y axes'
32593269
returnself._shared_y_axes
3260-
3261-

‎lib/matplotlib/tests/test_axes.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,6 +1708,19 @@ def test_vline_limit():
17081708
assertymax==0.25
17091709

17101710

1711+
@cleanup
1712+
deftest_empty_shared_subplots():
1713+
#empty plots with shared axes inherit limits from populated plots
1714+
fig,axes=plt.subplots(nrows=1,ncols=2,sharex=True,sharey=True)
1715+
axes[0].plot([1,2,3], [2,4,6])
1716+
x0,x1=axes[1].get_xlim()
1717+
y0,y1=axes[1].get_ylim()
1718+
assertx0<=1
1719+
assertx1>=3
1720+
asserty0<=2
1721+
asserty1>=6
1722+
1723+
17111724
if__name__=='__main__':
17121725
importnose
17131726
nose.runmodule(argv=['-s','--with-doctest'],exit=False)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp