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

Skip to content

Commit 28f63d0

Browse files
committed
FIX: change autolim exclude shapes not in data co-ordinates
1 parent 5cbff83 commit 28f63d0

12 files changed

+3811
-3770
lines changed

lib/matplotlib/collections.py

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ def __init__(self,
146146
self._joinstyle = None
147147

148148
self._offsets = np.zeros((1, 2))
149+
# save if offsets passed in were none...
150+
self._offsetsNone = offsets is None
149151
self._uniform_offsets = None
150152
if offsets is not None:
151153
offsets = np.asanyarray(offsets, float)
@@ -179,9 +181,30 @@ def get_offset_transform(self):
179181
return t
180182

181183
def get_datalim(self, transData):
184+
185+
# Get the automatic datalim of the collection.
186+
#
187+
# This operation depends on the transforms for the data in the
188+
# collection and whether the collection has offsets.
189+
#
190+
# 1) offsets = None, transform child of transData: use the paths for
191+
# the automatic limits (i.e. for LineCollection in streamline).
192+
# 2) offsets != None: offset_transform is child of transData:
193+
# a) transform is child of transData: use the path + offset for
194+
# limits (i.e for bar).
195+
# b) transform is not a child of transData: just use the offsets
196+
# for the limits (i.e. for scatter)
197+
# 3) otherwise return a null Bbox.
198+
182199
transform = self.get_transform()
183200
transOffset = self.get_offset_transform()
201+
if (not self._offsetsNone and
202+
not transOffset.contains_branch(transData)):
203+
# if there are offsets but in some co-ords other than data,
204+
# then don't use them for autoscaling.
205+
return transforms.Bbox.null()
184206
offsets = self._offsets
207+
185208
paths = self.get_paths()
186209

187210
if not transform.is_affine:
@@ -195,13 +218,32 @@ def get_datalim(self, transData):
195218
offsets = offsets.filled(np.nan)
196219
# get_path_collection_extents handles nan but not masked arrays
197220

221+
result = transforms.Bbox.null()
198222
if len(paths) and len(offsets):
199-
result = mpath.get_path_collection_extents(
200-
transform.frozen(), paths, self.get_transforms(),
201-
offsets, transOffset.frozen())
202-
result = result.inverse_transformed(transData)
203-
else:
204-
result = transforms.Bbox.null()
223+
if (not self._offsetsNone and
224+
not transform.contains_branch(transData)):
225+
# this is for collections that have their paths (shapes)
226+
# in physical, axes-relative, or figure-relative units
227+
# (i.e. like scatter). We can't uniquely set limits based on
228+
# those shapes, so we just set the limits based on their
229+
# location.
230+
# Finish the transform:
231+
offsets = transOffset.transform(offsets)
232+
offsets = transData.inverted().transform(offsets)
233+
offsets = np.ma.masked_invalid(offsets)
234+
extents = [[np.min(offsets[:, 0]), np.min(offsets[:, 1])],
235+
[np.max(offsets[:, 0]), np.max(offsets[:, 1])]]
236+
result = transforms.Bbox(extents)
237+
elif transform.contains_branch(transData):
238+
# collections that are just in data units (like quiver)
239+
# can properly have the axes limits set by their shape +
240+
# offset. LineCollections that have no offsets can
241+
# also use this algorithm (like streamplot).
242+
result = mpath.get_path_collection_extents(
243+
transform.frozen(), paths, self.get_transforms(),
244+
offsets, transOffset.frozen())
245+
result = result.inverse_transformed(transData)
246+
205247
return result
206248

207249
def get_window_extent(self, renderer):
@@ -1314,7 +1356,6 @@ def __init__(self, segments, # Can be None.
13141356
antialiaseds = (mpl.rcParams['lines.antialiased'],)
13151357

13161358
colors = mcolors.to_rgba_array(colors)
1317-
13181359
Collection.__init__(
13191360
self,
13201361
edgecolors=colors,
Binary file not shown.
Loading

lib/matplotlib/tests/baseline_images/test_axes/scatter.svg

Lines changed: 124 additions & 124 deletions
Loading
Binary file not shown.

0 commit comments

Comments
 (0)