[BUG] go.Heatmap making values NaN? px.imshow is correct
See original GitHub issueIssue:
For some reason, using go.Heatmap
causes values to be dropped/excluded from the plot. I’m guessing they’re being made NaN and filtered out somehow? px.imshow
correctly includes all values.
See here for the output from the code below: output
Versions: pandas: 1.40 plotly: 5.8.0
Reproducible code:
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
df = pd.DataFrame([[438, 160, 2, 3, 2]], index=["AB"], columns=["100015", "500015", "500030", "500039", "500078"])
print(df)
fig1 = go.Figure(
data=go.Heatmap(z=df.values, x=df.index, y=df.columns, colorbar=dict(title="count"), hoverongaps=False)
)
fig1.show()
fig2 = px.imshow(
df.values.T,
labels=dict(color="count"),
x=df.index,
y=df.columns,
)
fig2.show()
Issue Analytics
- State:
- Created a year ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
How can I plot NaN values as a special color with imshow in ...
I am trying to use imshow in matplotlib to plot data as a heatmap, but some of the values are NaNs. I'd like...
Read more >Issues - GitHub
[BUG] Go.Heatmap()/ px.imshow() breaks when mixing ints with strings, even if converting #2530. Open. Juanouo opened this issue on Jun 2, ...
Read more >How to deal with Heatmap NaN value - Plotly Community Forum
I have successfully using x, y, z value to create a heatmap. However, in my data, some have x, y value but did...
Read more >Creating annotated heatmaps — Matplotlib 3.6.2 documentation
Matplotlib's imshow function makes production of such plots particularly easy. The following examples show how to create a heatmap with annotations.
Read more >[Solved]-How can we plot data from a multi-index dataframe in ...
T # now restructure it for plotly dfp = df.stack("Venue").droplevel(0,0) # finally a simple plotly figure... px.imshow(dfp.values, x=dfp.columns, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It would be very challenging to implement this kind of warning at the
graph_objects
level unfortunately… That said,px.imshow
actually does provide this warning (trypx.imshow(df.values, x=df.index, y=df.columns)
) and this kind of thing is one of the reasons it’s generally recommended to usepx
wherever possible 😃Oh, I finally get it, thank you so much. Setting the axis names with different dimensions than the raw data cuts things off.
Do you think it’s worth adding some sort of warning when this happens (i.e. axis dimensions not aligning with input data)? Happy to close the issue if not.