Plotly version 4.3.0
import plotly.figure_factory as ff z = [[1,2,3], [4,5,6], [7,8,9]] fig = ff.create_annotated_heatmap(z, colorscale = 'Magma' ) fig.update_layout( autosize=False, width=500, height=500, ) fig
Also can be seen in the documentation.
In Contrast, Seaborn
import seaborn as sns z = [[1,2,3], [4,5,6], [7,8,9]] ax = sns.heatmap(z, annot=True)
The standard convention for matrices:
Most plotly plots like your standard line plot or scatter plot are on a cartesian coordinate system where the origin, (0,0), is the bottom left. Heatmaps, however, represent a matrix where the standard convention has the origin at the top left. Practically every python scientific library that deals with matrices has the origin at the top left:
- numpy arrays (z[0,0] corresponds to 1 in the original list z)
- python lists
- seaborn, matplotlib heatmaps
Now as noted in the git issue this can be solved to fit the above matrix layout as shown below, by updating autorange to “reversed”:
import plotly.figure_factory as ff z = [[1,2,3], [4,5,6], [7,8,9]] fig = ff.create_annotated_heatmap(z, colorscale='Magma') fig.update_yaxes(autorange="reversed") fig.update_layout( autosize=False, width=500, height=500, ) fig
The git issue mentions that this is still problematic because it changes the handedness of your plot and you may want to do further data comparisons, but i’m not sure I can think of a scenario where that would actually cause issues.
I wasn’t sure if this was an intentional design choice or would be an easy fix if not. Thank you.