qis.plot_corr_matrix_from_covar

qis.plot_corr_matrix_from_covar(covar, corr_format='{:.2f}', vol_format='{:.1%}', cmap='PiYG', title=True, ax=None, **kwargs)[source]

Plot a correlation matrix heatmap with volatilities on the diagonal.

Creates a lower-triangular correlation matrix heatmap where the diagonal displays volatilities (standard deviations) and the lower triangle shows correlations between variables. The upper triangle is masked (empty).

Parameters:
  • covar (pd.DataFrame) – Covariance matrix with variables as both index and columns. Must be a square symmetric matrix.

  • corr_format (str, optional) – Format string for correlation values in the lower triangle. Defaults to ‘{:.2f}’.

  • vol_format (str, optional) – Format string for volatility values on the diagonal. Defaults to ‘{:.1%}’.

  • cmap (str, optional) – Colormap name for the heatmap. Defaults to ‘PiYG’.

  • title (Optional[Union[str, bool]], optional) – Title for the plot. If True, uses default title. If False or None, no title is shown. If string, uses the provided title. Defaults to True.

  • ax (plt.Subplot, optional) – Matplotlib axes object to plot on. If None, creates a new figure. Defaults to None.

  • **kwargs – Additional keyword arguments passed to the underlying heatmap plotting function.

Returns:

Figure object containing the heatmap if ax is None,

otherwise None when plotting on provided axes.

Return type:

Optional[plt.Figure]

Note

The function converts the covariance matrix to correlations with the internal kernel npo._covar_to_corr_array, the one qis.covar_to_corr uses, and takes the volatilities it returns, the square roots of the diagonal covariance elements, in the units of covar. Grid lines are added around each cell for better visual separation.