-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Orientation of y-axis in Heatmap #413
Comments
Figured it out. Python example: plotly.graph_objs.Layout(
yaxis=dict(autorange='reversed')
) |
I agree, while one can do |
@elena-pascal did this ever get solved? |
@deliciouslytyped the issue had been closed a while back and I didn't reopen it just called into the void. Wasn't sure if it's affecting only me. Feel free to reopen if you feel strongly about it. |
I think I'd have to post a new issue. |
@elena-pascal I think something truly needs to be done, as I am in a point in a project when a lot of time got wasted just to find ways around. |
Hi @elena-pascal @Shivamshaiv @deliciouslytyped could you please explain why
is not a solution for you? Also note that |
The Plotly heatmap is intended to represent a discrete version of a scalar field, z= f(x, y), with x, y in a rectangle [a b] x [c, d]. Generally people consider as being the "default definition" that given in a library they used before. |
It is the matrix representation aspect as described above. Simply reversing the axis messes up the handedness (I need to differentiate between front and back too) of the plotted matrix, and for a complicated geometry loosing this bit of sanity is undesirable. |
Thank you for your answer, but I don't understand the "handedness". Maybe a schematic drawing would help? Did you try passing your data to |
Most matrix maths implies right handed coordinate Cartesian systems (the left image). Flipping one axis is such a system results in having a left handed coordinate system (the right image). Moving from one to another is a pain as the definition of operations, eg rotation, must change. I know this can be a problem because we tried for years to compare different handedness images and left many scratching their heads. Tbh, I don't quite remember now why I wanted to use heatmap and not imshow. |
Is there some reason this would be hard to implement? I don't remember the details - it's been a long time since I fought with this issue - but it should just be a simple coordinate transformation on the backend that if we try to fix from the calling side, ends up complicating things unnecessarily. Since there's things like
I see no reason why what we want shouldn't be. TL;DR: I don't remember what the problem was, but I strongly believe it's valid and I don't see why it would be difficult to fix. And It should be fixed in the library. IIRC it's a major usability pain point if you need it. |
I'll just open a new issue pointing to this one. |
I'm really having trouble understanding the nature of the concern here with "handedness"... Here is what I see today with the default option and the reversed-axis option. The underlying data doesn't change, there's just one argument set to flip the coordinate system at display-time. If this isn't sufficient, what would be? |
@nicolaskruchten I'm not sure this will help, but add another gradient on the other axis so that it's not symmetric. |
Yes, the x and/or y axes can be flipped and in this case only the y axis was flipped. |
You can actually tell by looking at the tick labels :) |
Oh yeah. I think that might have actually been my original problem. :) (not sure though) |
Ok! “problem” in what sense? I’m struggling to see what is not possible today, give that all 4 possible combinations of x/y flip/no-flip are available :) |
I think what we're asking for is a matrix option for heatmap that defaults origin to top left. That would probably be the pythonic way. The problem is that while heatmap is happy to take a numpy matrix as input, its shown origin is flipped with respect to the usual understanding of the y axis of a matrix. If the matrix has meaning in 3 dimensions than that also affects the z axis, or viewing direction. If a user is not careful and wants to look at matrices with histogram they will run into problems. Let's consider a matrix: Let's say I want to visualize how a 3D 90 degrees rotation around the normal to the image plane looks like for this matrix. If I use the standard definition of rotation then it should be something like this: The rotation behaviour is going to be opposite than expected if I were to be more naive about orientations. While inversing y axis achieves the correct image, and it could well be a solution for visualizing individual images, I don't think it is a good (sane) solution for matrix plotting with heatmap. The user is required to have a good understanding of the effect of axis flipping and why they have to flip y back. This can be tricky to be comfortable with since inversing axes in a matrix comes with more implications, eg affecting handedness, and I think this thread was proof that thinking about 3D orientations is a pain. For me personally, I know that seeing a flipped axis in the code will make me want to double check every time the sanity of the orientations. summary: I would prefer to have a matrix plotting option that does not invert axes because axes inversion in linear algebra makes me very nervous. |
Thanks for the extra context @elena-pascal, I think I'm understanding. A couple of points of context from the Plotly.py maintenance perspective:
I guess the bottom-line good news is that we do in fact already have built-in functionality in Plotly to display matrix-like data the way you would expect, without forcing you to explicitly declare anything as |
Thank you for explaining the implementation implications and taking the time to listen to our concerns. Yes, I do agree that changing the default would be a nightmare that would benefit way fewer people than those it would negatively affect. Under-the-hood implementation is all I hoped for: I imagined a I'll remember to use |
Taking into account that @elena-pascal considers that some users can have difficulties in undestanding why to get a heatmap as an image referenced to a left handed coordinate system we are performing an upside-down image flipping (i.e. The relationship between the coordinates (x,y), and (X,Y) of a pixel is as follows:
and conversely:
But these relations point out that getting the coordinates (X Y) from (x,y) or reciprocally amounts |
The default orientation of the y-axis in the Heatmap graph is, at least to me, unexpected. The 0,0 coordinate of the plot is in the lower left corner. A heatmap is generally used to display a matrix, such as an image, however, and the 0,0 index into the matrix would be in the top left corner. An image is thus displayed flipped upside down. One can of course flip the
z
array or provide the values fory
in reversed order, but this keeps the labelling of the axis and the display of y,x in the hover window unaffected. I like the way this is handled inmatplotlib.pyplot.imshow
, which provides anorigin
argument.An additional argument for the
Heatmap
graph to control the orientation of the y-axis would be nice.The text was updated successfully, but these errors were encountered: