Correlation heatmap

后端 未结 4 1864
傲寒
傲寒 2020-11-29 20:07

I want to represent correlation matrix using a heatmap. There is something called correlogram in R, but I don\'t think there\'s such a thing in Python.

How can I do

4条回答
  •  春和景丽
    2020-11-29 20:17

    If your data is in a Pandas DataFrame, you can use Seaborn's heatmap function to create your desired plot.

    import seaborn as sns
    
    Var_Corr = df.corr()
    # plot the heatmap and annotation on it
    sns.heatmap(Var_Corr, xticklabels=Var_Corr.columns, yticklabels=Var_Corr.columns, annot=True)
    

    Correlation plot

    From the question, it looks like the data is in a NumPy array. If that array has the name numpy_data, before you can use the step above, you would want to put it into a Pandas DataFrame using the following:

    import pandas as pd
    df = pd.DataFrame(numpy_data)
    

提交回复
热议问题