FIX: bypass inverse in collection#17206
Conversation
5f878c1 to
20ab0fa
Compare
20ab0fa to
229b49e
Compare
229b49e to
a53833e
Compare
|
This works for me, |
dstansby
left a comment
There was a problem hiding this comment.
👍 works for me, thanks for the quick investigation and fix!
|
Untested, but I think something along the lines of the following may work too, be simpler, and cover more cases? diff --git i/lib/matplotlib/collections.py w/lib/matplotlib/collections.py
index 181e46b45..55a681000 100644
--- i/lib/matplotlib/collections.py
+++ w/lib/matplotlib/collections.py
@@ -211,8 +211,6 @@ class Collection(artist.Artist, cm.ScalarMappable):
# we may have transform.contains_branch(transData) but not
# transforms.get_affine().contains_branch(transData). But later,
# be careful to only apply the affine part that remains.
- if not transOffset.is_affine:
- offsets = transOffset.transform_non_affine(offsets)
if isinstance(offsets, np.ma.MaskedArray):
offsets = offsets.filled(np.nan)
@@ -226,7 +224,8 @@ class Collection(artist.Artist, cm.ScalarMappable):
# also use this algorithm (like streamplot).
result = mpath.get_path_collection_extents(
transform.get_affine(), paths, self.get_transforms(),
- offsets, transOffset.get_affine().frozen())
+ transOffset.transform_non_affine(offsets),
+ transOffset.get_affine().frozen())
return result.transformed(transData.inverted())
if not self._offsetsNone:
# this is for collections that have their paths (shapes)
@@ -234,14 +233,13 @@ class Collection(artist.Artist, cm.ScalarMappable):
# (i.e. like scatter). We can't uniquely set limits based on
# those shapes, so we just set the limits based on their
# location.
- # Finish the transform:
- offsets = (transOffset.get_affine() +
- transData.inverted()).transform(offsets)
+ offsets = (transOffset - transData).transform(offsets)
offsets = np.ma.masked_invalid(offsets)
if not offsets.mask.all():
points = np.row_stack((offsets.min(axis=0),
offsets.max(axis=0)))
return transforms.Bbox(points)
+
return transforms.Bbox.null()
def get_window_extent(self, renderer):The point is that |
|
I really don't understand why transforms were implemented with add and minus to really mean multiplication and multiplication by the inverse. Worse, these operators are, as far as I can tell, completely undocumented. So I'm not in favour of adding them to the code until this situation improves. |
Woah, that is confusing! I was looking at your changelog and got really confused with what was happening because it never crossed my mind that + could ever mean multiplying two transformations together. |
|
I should stipulate that |
|
There was one transform operator in the code before (an addition: As to why multiplication and division are implemented as addition and subtraction: I didn't make that choice so I can't tell, but it's not a completely silly choice either. In particular, if you follow the matrix multiplication semantics, you'd have |
Ha ha, guess why? I've implement it with the minus sign and put a comment. The extra code in |
|
... added a simple test as well.. |
|
Owee, I'm MrMeeseeks, Look at me. There seem to be a conflict, please backport manually. Here are approximate instructions:
And apply the correct labels and milestones. Congratulation you did some good work ! Hopefully your backport PR will be tested by the continuous integration and merged soon! If these instruction are inaccurate, feel free to suggest an improvement. |
|
OK, I have real troubles manually backporting: Like maybe this PR isn't worth back porting, but the instructions used to work |
Works fine for me on a fresh git clone, maybe you need to |
…3.2.x Merge pull request #17206 from jklymak/fix-bypass-inverse-collection
PR Summary
I think this fixes #17203. If anyone has a dev environment where #17203 is triggered can you test this? It bypasses transforming the offsets if the offset transform and the data transform are the same.
PR Checklist