question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Orientation of y-axis in Heatmap

See original GitHub issue

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 for y 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 in matplotlib.pyplot.imshow, which provides an origin argument. An additional argument for the Heatmap graph to control the orientation of the y-axis would be nice.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:23 (7 by maintainers)

github_iconTop GitHub Comments

7reactions
hackermdcommented, Mar 3, 2016

Figured it out. Python example:

plotly.graph_objs.Layout(
    yaxis=dict(autorange='reversed')
)
2reactions
nicolaskruchtencommented, Mar 12, 2020

Thanks for the extra context @elena-pascal, I think I’m understanding.

A couple of points of context from the Plotly.py maintenance perspective:

  1. The meaning of "reversed" is with respect to an origin at the bottom left, which stems from the fact that the underlying layout engine for Plotly.py supports the plotting of multiple traces of different types on the same plot e.g. a heatmap and a scatter, and I suspect the scatter was implemented first.
  2. We cannot really change the defaults without making some possibly-large existing population of users unhappy, because whatever code they have today would unexpectedly result in upside-down heatmaps after an upgrade i.e. this would be a breaking change to our API. Notably, anyone using something like Datashader to overcome overplotting on scatterplots will have the same issue you are facing with respect to default behaviour.
  3. If we did change the defaults, the mechanism whereby we would do so is that we would set yaxis_autorange="reversed" on all plots containing only heatmap traces. This is actually what we do for plots containing only image traces. We made this choice basically because we agree with you! We were able to do this without triggering a “breaking change” when initially implementing image last fall because there was no pre-existing code relying on the other behaviour.
  4. Setting yaxis_autorange="reversed" is exactly what Plotly.js implicitly does under the hood for plots with only image traces and what px.imshow explicitly does under the hood to implement its default origin="upper" option, which works both with single-channel heatmap/matrix-like data and with multi-channel image-like data.

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 "reversed": if you use px.imshow and leave the origin setting alone. The bad news is that if you inspect the figure (i.e. print(fig)), you will see a possibly-confusing autorange="reversed" in the y-axis, and there’s no way we can change that without upsetting other people.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Changing the rotation of tick labels in Seaborn heatmap
The problem I ran into was with using Heatmap through Seaborn, and FacetGrid. I could rotate the x-axis ticks, but not the y-axis...
Read more >
Rotating axis labels in matplotlib and seaborn
Here we have the classic problem with categorical data: we need to display all the labels and because some of them are quite...
Read more >
Heatmap Axis Labels Printing Vertically? - MATLAB Answers
The heatmap's X labels orientation is dynamically determined based on the number of labels and the axes width. In other words, if you...
Read more >
AxisModel API in Angular HeatMap API component - Syncfusion
Checkout and learn about AxisModel API in Angular HeatMap API component of ... boolean. Enable Trim for heatmap yAxis ... The angle to...
Read more >
Axis Orientation | Axes and Grids - AnyChart Documentation
chart.xAxis().orientation("top"); chart.yAxis ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found