Annotate heatmap with value from Pandas dataframe

前端 未结 4 1048
野的像风
野的像风 2021-02-04 20:59

I would like to annotate a heatmap with the values that I pass from a dataframe into the function below. I have looked at matplotlib.text but have not been able to get the value

4条回答
  •  故里飘歌
    2021-02-04 21:55

    You also can use plotly.figure_factory to create heatmap from DataFrame, but you have convert it into list.

        import plotly.figure_factory as ff
    
        z = [your_dataframe].values.tolist()
        x = [your_dataframe].columns.tolist()
        y = [your_dataframe].index.tolist()
    
        fig = ff.create_annotated_heatmap(z, x=x, y=y, annotation_text=z, colorscale='viridis')
    
        # for add annotation into Heatmap
        for i in range(len(fig.layout.annotations)):
            fig.layout.annotations[i].font.size = 12
    
        # show your Heatmap
        fig.show()
    

提交回复
热议问题