You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 Affine transformations (might also be for other transformations, that's just where I noticed it).
Say we are applying an affine transformation to our blobs polygons, 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 of basic.show(), the axis limits are adapted according to the extent - I only got the datashader plot above by manually overwriting the extent).
@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 😅
@LucaMarconato I have an approach right now in #378 that works for Identity, Scale and Affine and 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 a Sequence we 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 for MapAxis and Translation, 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"?
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
Affine
transformations (might also be for other transformations, that's just where I noticed it).Say we are applying an affine transformation to our
blobs
polygons, 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)
The text was updated successfully, but these errors were encountered: