Search code examples
pythonplotlypivotheatmap

Percentage of Row Total in Heatmap Python


I would like to show the numbers as percentage of Row (or Column) Total for this heatmap. I am using Plotly library for the plotting. enter image description here

I could find a way to get the percentage of row total using code below. I would really appreciate any help to plot these percentages in a heatmap for better visualisation.

enter image description here


Solution

  • You can use px.imshow() to create a heatmap for your dataframe such that:

    import plotly.express as px
    fig = px.imshow(pivotdf_unstack, text_auto=True, aspect="auto")
    fig.show()
    

    You can replace the null values with any suitable values you think. You will get a heatmap with null values like:

    enter image description here