Repository navigation
Transformations with flipped y-axis #381
Description
Activity
- addedshapes 🫧Anything related to ShapesAnything related to Shapes🗣️ discussionNeeds further discussionNeeds further discussion
on Nov 5, 2024 @LucaMarconato any thoughts on this? Our current best guess is "do what matplotlib is doing" so we don't change all plots created to date with the library 😅
Sorry I started working on this but then things got into my way. I'll get back to this soon.
Reacted by Tim Treis and Sonja-StockhausSonja-Stockhaus commented
on Nov 27, 2024 CollaboratorAuthorMore actions@LucaMarconato I have an approach right now in #378 that works for
Identity, ScaleandAffineand all sorts of sequences of the three. The idea is to first reflect all points along the x-axis by multiplying with[[1, 0], [0, -1]], then apply the transformation(s) (multiply with the affine matrix - for aSequencewe need to reverse the order of the transformations first) and flip back by once again multiplying with our flip matrix.This gives the same results as
matplotlib. The only problem is that the same approach doesn't work forMapAxisandTranslation, so I will probably just try to write a method that checks for the type of each transformation and treats it accordingly (e.g. don't flip before MapAxis).If you find the time it would just be interesting to know what you think about the idea that a rotation to the right should be done to the left on a flipped y-axis, aka the matplotlib result is "incorrect"?
Reacted by LucaMarconato- linked a pull request that will close this issueSimplify affine matrix calculation for datashader #424
on Feb 17, 2025 - linked a pull request that will close this issueSimplified affine matrix calculation for datashader #491
on Sep 23, 2025 Thanks @Sonja-Stockhaus for finding a solution! I am working on transformations on the NGFF side, once I will change that maybe the problem will disappear on its own (or happy to have a look again after that). For the moment I think your fix is great.
Reacted by Sonja-Stockhaus
Sth I encountered while working on #337: when using datashader, transformations of points and shapes need to be applied before rendering. I think the flipping of the y-axis leads to an inconsistency when applying
Affinetransformations (might also be for other transformations, that's just where I noticed it).Say we are applying an affine transformation to our
blobspolygons, namely a rotation 90° to the right (around 0/0), and then render:If I get this correctly, a point can be transformed by performing matrix multiplication with the affine matrix of the transformation, such as
np.array([1, 1]) @ np.array([[0, -1], [1, 0]])which gives[1, -1], therefore rotation by 90° to the right around the point 0/0.The original image of the blobs polygons without any transformation looks like this:

And the code above (using matplotlib) gives us

Which looks like a rotation to the right around 0/0. However, my question here is that when you flip the y-axis, wouldn't any rotation to the right look like a rotation to the left instead?
My current solution for datashader simply performs the matrix multiplication of all points of the polygons with the transformation matrix. This is all in a "normal", not flipped coordinate system, so when you flip the axes, you would get something like this:

(Looks like a rotation to the left, because the y-axis is flipped).
@LucaMarconato since you're the master of transformations, could you have a look and tell me what you think about it? Is this intended behavior since it is more intuitive for the user?
If yes: do you know an easy way how to get the affine matrix to do the transformation in the y-axis-not-flipped scenario (especially thinking about sequences of transformations...)
If no: the matplotlib version would be "incorrect" and I think
get_extent()as well, since it gives us exactly the values that we see in the matplotlib plot (and that's a problem, because in the very end ofbasic.show(), the axis limits are adapted according to the extent - I only got the datashader plot above by manually overwriting the extent).(cc: @timtreis)