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

Skip to content

Commit ffeeeef

Browse files
committed
Merge pull request #17017 from jklymak/fix-blended-transform
FIX: force blended transforms with data to be in data space
1 parent 8ac76de commit ffeeeef

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lib/matplotlib/collections.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def get_datalim(self, transData):
221221
# get_path_collection_extents handles nan but not masked arrays
222222

223223
if len(paths) and len(offsets):
224-
if transform.contains_branch(transData):
224+
if any(transform.contains_branch_seperately(transData)):
225225
# collections that are just in data units (like quiver)
226226
# can properly have the axes limits set by their shape +
227227
# offset. LineCollections that have no offsets can

lib/matplotlib/tests/test_collections.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,3 +718,27 @@ def test_EventCollection_nosort():
718718
arr = np.array([3, 2, 1, 10])
719719
coll = EventCollection(arr)
720720
np.testing.assert_array_equal(arr, np.array([3, 2, 1, 10]))
721+
722+
723+
def test_collection_set_verts_array():
724+
verts = np.arange(80, dtype=np.double).reshape(10, 4, 2)
725+
col_arr = PolyCollection(verts)
726+
col_list = PolyCollection(list(verts))
727+
assert len(col_arr._paths) == len(col_list._paths)
728+
for ap, lp in zip(col_arr._paths, col_list._paths):
729+
assert np.array_equal(ap._vertices, lp._vertices)
730+
assert np.array_equal(ap._codes, lp._codes)
731+
732+
733+
def test_blended_collection_autolim():
734+
a = [1, 2, 4]
735+
height = .2
736+
737+
xy_pairs = np.column_stack([np.repeat(a, 2), np.tile([0, height], len(a))])
738+
line_segs = xy_pairs.reshape([len(a), 2, 2])
739+
740+
f, ax = plt.subplots()
741+
trans = mtransforms.blended_transform_factory(ax.transData, ax.transAxes)
742+
ax.add_collection(LineCollection(line_segs, transform=trans))
743+
ax.autoscale_view(scalex=True, scaley=False)
744+
np.testing.assert_allclose(ax.get_xlim(), [1., 4.])

0 commit comments

Comments
 (0)