Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. import seaborn as sns
  2. def heatMap(df, mirror):
  3.  
  4. # Create Correlation df
  5. corr = df.corr()
  6. # Plot figsize
  7. fig, ax = plt.subplots(figsize=(20, 20))
  8. # Generate Color Map
  9. colormap = sns.diverging_palette(220, 10, as_cmap=True)
  10.  
  11. if mirror == True:
  12. #Generate Heat Map, allow annotations and place floats in map
  13. sns.heatmap(corr, cmap=colormap, annot=True, fmt=".2f")
  14. #Apply xticks
  15. plt.xticks(range(len(corr.columns)), corr.columns);
  16. #Apply yticks
  17. plt.yticks(range(len(corr.columns)), corr.columns)
  18. #show plot
  19.  
  20. else:
  21. # Drop self-correlations
  22. dropSelf = np.zeros_like(corr)
  23. dropSelf[np.triu_indices_from(dropSelf)] = True
  24. # Generate Color Map
  25. colormap = sns.diverging_palette(220, 10, as_cmap=True)
  26. # Generate Heat Map, allow annotations and place floats in map
  27. sns.heatmap(corr, cmap=colormap, annot=True, fmt=".2f", mask=dropSelf)
  28. # Apply xticks
  29. plt.xticks(range(len(corr.columns)), corr.columns);
  30. # Apply yticks
  31. plt.yticks(range(len(corr.columns)), corr.columns)
  32. # show plot
  33. plt.show()
  34.  
  35.  
  36. heatMap(df,mirror=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement