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

Skip to content

Commit 7e69d18

Browse files
committed
Propagate minpos from Collections to Axes.dataLim.
This ensures that autoscaling on log scales is correct.
1 parent f70df4c commit 7e69d18

4 files changed

Lines changed: 21 additions & 11 deletions

File tree

lib/matplotlib/axes/_base.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2000,7 +2000,13 @@ def add_collection(self, collection, autolim=True):
20002000
# Make sure viewLim is not stale (mostly to match
20012001
# pre-lazy-autoscale behavior, which is not really better).
20022002
self._unstale_viewLim()
2003-
self.update_datalim(collection.get_datalim(self.transData))
2003+
datalim = collection.get_datalim(self.transData)
2004+
# By definition, p0 <= minpos <= p1, so minpos would be
2005+
# unnecessary. However, we add minpos to the call so that
2006+
# self.dataLim will update its own minpos. This ensures that log
2007+
# scales see the correct minimum.
2008+
self.update_datalim(
2009+
np.row_stack([datalim.p0, datalim.minpos, datalim.p1]))
20042010

20052011
self.stale = True
20062012
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)