Example #1
0
 def visualize_correlation_matrix(
     self,
     corr,
     features_list: list,
     annot: bool = False,
     plot_title: str = None,
     ts_title: bool = True,
     save_image: bool = False,
     output_fp: str = None,
     ts_output_fp: bool = False,
     show: bool = True,
 ) -> object:
     """
     Graphs df correlation with diagonal matrix. Suitable for lots of
     features as it doesn't display annotations. Optionally saves output
     to image.
     https://seaborn.pydata.org/examples/many_pairwise_correlations.html
     """
     # Generate a mask for the upper triangle
     mask = np.triu(np.ones_like(corr, dtype=np.bool))
     mask[np.triu_indices_from(mask)] = True
     # Set up the matplotlib figure
     f, ax = plt.subplots(figsize=(11, 9))
     # Draw the heatmap with the mask and correct aspect ratio
     hmap = sbn.heatmap(
         corr,
         annot=annot,
         mask=mask,
         cmap=cmap,
         vmax=1,
         vmin=-1,
         center=0,
         xticklabels=features_list,
         yticklabels=features_list,
         square=True,
         fmt=".2g",
         linewidths=0.5,
         cbar_kws={"shrink": 0.5},
         annot_kws={"size": 6},
     )
     ts = Misc.make_ts()
     plot_title_to_show = self._make_plot_title(ts, plot_title, ts_title)
     plt.title(plot_title_to_show)
     if save_image:
         self._save_image(ts, output_fp, plot_title, ts_output_fp)
     if show:
         plt.show()
     return hmap