Reputation: 11
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
Upvotes: 1
Views: 1485
Reputation: 115
To suppress this output assign the return object a name:
_ = plt.plot(A)
or
plot(A);
Upvotes: 2