From 27ab2060cfa7511e2d25f7d520c4050dd56e7cae Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Fri, 5 Nov 2021 03:38:01 -0400 Subject: [PATCH] Ignore transOffset if no offsets passed to Collection This fixes a regression from #20717 in networkx (Fixes #21517), but we'll go forward with the change in a later release to give them time to fix it. --- .../api_changes_3.5.0/deprecations.rst | 4 ++++ lib/matplotlib/collections.py | 12 ++++++++++++ lib/matplotlib/tests/test_collections.py | 7 ++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/doc/api/prev_api_changes/api_changes_3.5.0/deprecations.rst b/doc/api/prev_api_changes/api_changes_3.5.0/deprecations.rst index 3118c2bca0e6..2132e0faf9db 100644 --- a/doc/api/prev_api_changes/api_changes_3.5.0/deprecations.rst +++ b/doc/api/prev_api_changes/api_changes_3.5.0/deprecations.rst @@ -269,6 +269,10 @@ Miscellaneous deprecations - ``cm.LUTSIZE`` is deprecated. Use :rc:`image.lut` instead. This value only affects colormap quantization levels for default colormaps generated at module import time. +- ``Collection.__init__`` previously ignored *transOffset* without *offsets* also + being specified. In the future, *transOffset* will begin having an effect + regardless of *offsets*. In the meantime, if you wish to set *transOffset*, + call `.Collection.set_offset_transform` explicitly. - ``Colorbar.patch`` is deprecated; this attribute is not correctly updated anymore. - ``ContourLabeler.get_label_width`` is deprecated. diff --git a/lib/matplotlib/collections.py b/lib/matplotlib/collections.py index 619c62b5ca14..562362ab0c37 100644 --- a/lib/matplotlib/collections.py +++ b/lib/matplotlib/collections.py @@ -202,6 +202,18 @@ def __init__(self, if offsets.shape == (2,): offsets = offsets[None, :] self._offsets = offsets + elif transOffset is not None: + _api.warn_deprecated( + '3.5', + removal='3.6', + message='Passing *transOffset* without *offsets* has no ' + 'effect. This behavior is deprecated since %(since)s ' + 'and %(removal)s, *transOffset* will begin having an ' + 'effect regardless of *offsets*. In the meantime, if ' + 'you wish to set *transOffset*, call ' + 'collection.set_offset_transform(transOffset) ' + 'explicitly.') + transOffset = None self._transOffset = transOffset diff --git a/lib/matplotlib/tests/test_collections.py b/lib/matplotlib/tests/test_collections.py index a80c8d717416..9f92206e51cb 100644 --- a/lib/matplotlib/tests/test_collections.py +++ b/lib/matplotlib/tests/test_collections.py @@ -1072,8 +1072,13 @@ def test_set_offsets_late(): def test_set_offset_transform(): + with pytest.warns(MatplotlibDeprecationWarning, + match='.transOffset. without .offsets. has no effect'): + mcollections.Collection([], + transOffset=mtransforms.IdentityTransform()) + skew = mtransforms.Affine2D().skew(2, 2) - init = mcollections.Collection([], transOffset=skew) + init = mcollections.Collection([], offsets=[], transOffset=skew) late = mcollections.Collection([]) late.set_offset_transform(skew)