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

Skip to content

Commit 898fd1c

Browse files
committed
Propagate minpos from Collections to Axes.dataLim.
This ensures that autoscaling on log scales is correct.
1 parent ba92e95 commit 898fd1c

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1990,7 +1990,13 @@ def add_collection(self, collection, autolim=True):
19901990
# Make sure viewLim is not stale (mostly to match
19911991
# pre-lazy-autoscale behavior, which is not really better).
19921992
self._unstale_viewLim()
1993-
self.update_datalim(collection.get_datalim(self.transData))
1993+
datalim = collection.get_datalim(self.transData)
1994+
# By definition, p0 <= minpos <= p1, so minpos would be
1995+
# unnecessary. However, we add minpos to the call so that
1996+
# self.dataLim will update its own minpos. This ensures that log
1997+
# scales see the correct minimum.
1998+
self.update_datalim(
1999+
np.row_stack([datalim.p0, datalim.minpos, datalim.p1]))
19942000

19952001
self.stale = True
19962002
return collection

lib/matplotlib/collections.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,11 @@ def get_datalim(self, transData):
274274
# can properly have the axes limits set by their shape +
275275
# offset. LineCollections that have no offsets can
276276
# also use this algorithm (like streamplot).
277-
result = mpath.get_path_collection_extents(
278-
transform.get_affine(), paths, self.get_transforms(),
277+
return mpath.get_path_collection_extents(
278+
transform.get_affine() - transData, paths,
279+
self.get_transforms(),
279280
transOffset.transform_non_affine(offsets),
280281
transOffset.get_affine().frozen())
281-
return result.transformed(transData.inverted())
282282
if not self._offsetsNone:
283283
# this is for collections that have their paths (shapes)
284284
# in physical, axes-relative, or figure-relative units
@@ -290,9 +290,9 @@ def get_datalim(self, transData):
290290
# note A-B means A B^{-1}
291291
offsets = np.ma.masked_invalid(offsets)
292292
if not offsets.mask.all():
293-
points = np.row_stack((offsets.min(axis=0),
294-
offsets.max(axis=0)))
295-
return transforms.Bbox(points)
293+
bbox = transforms.Bbox.null()
294+
bbox.update_from_data_xy(offsets)
295+
return bbox
296296
return transforms.Bbox.null()
297297

298298
def get_window_extent(self, renderer):

lib/matplotlib/path.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1042,4 +1042,4 @@ def get_path_collection_extents(
10421042
extents, minpos = _path.get_path_collection_extents(
10431043
master_transform, paths, np.atleast_3d(transforms),
10441044
offsets, offset_transform)
1045-
return Bbox.from_extents(*extents)
1045+
return Bbox.from_extents(*extents, minpos=minpos)

lib/matplotlib/transforms.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -808,13 +808,17 @@ def from_bounds(x0, y0, width, height):
808808
return Bbox.from_extents(x0, y0, x0 + width, y0 + height)
809809

810810
@staticmethod
811-
def from_extents(*args):
811+
def from_extents(*args, minpos=None):
812812
"""
813813
Create a new Bbox from *left*, *bottom*, *right* and *top*.
814814
815-
The *y*-axis increases upwards.
815+
The *y*-axis increases upwards. Optionally, passing *minpos* will set
816+
that property on the returned Bbox.
816817
"""
817-
return Bbox(np.reshape(args, (2, 2)))
818+
bbox = Bbox(np.reshape(args, (2, 2)))
819+
if minpos is not None:
820+
bbox._minpos[:] = minpos
821+
return bbox
818822

819823
def __format__(self, fmt):
820824
return (

0 commit comments

Comments
 (0)