, titles=None, ncols=None, normcolor=False, xnames=None, ynames=None, fig=None, cmap='RdYlBu_r')[source]

Create a grid of correlation plots.

The individual correlation plots are assumed to all have the same variables, axis labels can be specified only once.

dcorrslist or iterable of ndarrays

List of correlation matrices.

titleslist[str], optional

List of titles for the subplots. By default no title are shown.

ncolsint, optional

Number of columns in the subplot grid. If not given, the number of columns is determined automatically.

normcolorbool or tuple, optional

If False (default), then the color coding range corresponds to the range of dcorr. If True, then the color range is normalized to (-1, 1). If this is a tuple of two numbers, then they define the range for the color bar.

xnameslist[str], optional

Labels for the horizontal axis. If not given (None), then the matplotlib defaults (integers) are used. If it is an empty list, [], then no ticks and labels are added.

ynameslist[str], optional

Labels for the vertical axis. Works the same way as xnames. If not given, the same names as for xnames are re-used.

figFigure, optional

If given, this figure is simply returned. Otherwise a new figure is created.

cmapstr or Matplotlib Colormap instance, optional

The colormap for the plot. Can be any valid Matplotlib Colormap instance or name.


If ax is None, the created figure. Otherwise the figure to which ax is connected.


>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> import statsmodels.api as sm

In this example we just reuse the same correlation matrix several times. Of course in reality one would show a different correlation (measuring a another type of correlation, for example Pearson (linear) and Spearman, Kendall (nonlinear) correlations) for the same variables.

>>> hie_data = sm.datasets.randhie.load_pandas()
>>> corr_matrix = np.corrcoef(
>>>[corr_matrix] * 8, xnames=hie_data.names)

(Source code, png, hires.png, pdf)


Last update: Feb 14, 2024