Search code examples
pythonpandasplotly

Heatmap based on DataFrame


The Dataframe

import pandas as pd
import plotly.express as px

df = pd.DataFrame({"A":[1,2,3],"B":[4,5,6]})
print(df)

   A  B
0  1  4
1  2  5
2  3  6

transformed into a heatmap using

fig = px.density_heatmap(df)
fig.show()

results in

enter image description here

What I actually want, is the index (0,1,3) on the x-axis, column names (A,B) on the y axis and the actual cell values represented by colors, as a third dimension. How can I get that representation?


Solution

  • You might want to use px.imshow:

    px.imshow(df)
    

    enter image description here