Annotate heatmap with value from Pandas dataframe

前端 未结 4 1040
野的像风
野的像风 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:37

    This functionality is provided by the seaborn package. It can produce maps like

    An example usage of seaborn is

    import seaborn as sns
    sns.set()
    
    # Load the example flights dataset and conver to long-form
    flights_long = sns.load_dataset("flights")
    flights = flights_long.pivot("month", "year", "passengers")
    
    # Draw a heatmap with the numeric values in each cell
    sns.heatmap(flights, annot=True, fmt="d", linewidths=.5)
    

提交回复
热议问题