1

All - reaching out for some guidance, if any available, to help solve this somewhat frustrating issue.

I am defining a function that creates a correlation matrix using Seaborn's annotated heatmap. The function works fine, however, the Seaborn output is being produced automatically upon running the function without having to call it.

I wish to suppress this output and only produce it later on in the notebook when calling the correlation matrix, as you would do with a dataframe, other graph, etc.

Any solutions? So far, I have tried adding semi-colons, put.ioff(), different assignments to the graph/axis objects. To be honest, I am not sure if this is a Seaborn issue or one related to Matplotlib. Maybe the function could be written in an alternative way to mitigate this limitation?

Code below. Any help on this would be greatly appreciated, many thanks.

# cormat is a correlation matrix

import matplotlib.pyplot as plt

def correl_heatmap(cormat):
    _f01, ax = plt.subplots(figsize=(cormat.shape[0], cormat.shape[0]));
    sns.heatmap(cormat,
                vmin=-1, vmax=1, center=0, square=True, 
                annot=True, cmap='coolwarm_r', cbar_kws={'shrink': 0.8}, ax=ax);
    ax.set_xticklabels(ax.get_xticklabels(),
                       rotation=90,
                       horizontalalignment='center');
    ax.set_yticklabels(ax.get_yticklabels(),
                       rotation=90,
                       verticalalignment='center');
    return _f01



_f01 = correl_heatmap(cormat)
_f01
paradocs
  • 11
  • 1
  • 1
    Does this answer your question? [How do you suppress output in IPython Notebook?](https://stackoverflow.com/questions/23692950/how-do-you-suppress-output-in-ipython-notebook) – DavidG May 28 '20 at 13:34
  • Thanks but I'm afraid not – paradocs May 28 '20 at 16:48

1 Answers1

2

To suppress this output assign the return object a name:

_ = plt.plot(A)

or

plot(A);