26
$\begingroup$

I create a corr() df out of an original df. The corr() df came out 70 X 70 and it is impossible to visualize the heatmap... sns.heatmap(df). If I try to display the corr = df.corr(), the table doesn't fit the screen and I can see all the correlations. Is it a way to either print the entire df regardless of its size or to control the size of the heatmap?

enter image description here

$\endgroup$
3
  • $\begingroup$ I'm a little confused, do you want to print df.corr() or change the size of the heatmap? $\endgroup$
    – Icyblade
    Mar 13, 2017 at 1:52
  • $\begingroup$ @Gilbert You can do masking of the heatmap such that either the upper half or the lower half are only displayed $\endgroup$
    – enterML
    Mar 13, 2017 at 9:45
  • $\begingroup$ Ideally, I want to increase the heatmap size. $\endgroup$
    – redeemefy
    Mar 13, 2017 at 14:47

6 Answers 6

27
$\begingroup$

I found out how to increase the size of my plot with the following code...

plt.subplots(figsize=(20,15))
sns.heatmap(corr)

enter image description here

$\endgroup$
1
  • $\begingroup$ Check the answer yourself please :-) $\endgroup$
    – Icyblade
    Mar 14, 2017 at 7:15
4
$\begingroup$

This would also work.

plt.figure(figsize=(20,15))
ax=subplot(111)
sns.heatmap(corr,ax=ax)
$\endgroup$
0
$\begingroup$
plt.figure(figsize=(20,15))

plt is not always defined, I can use seaborn without plt.

To use the above line you need to also import plt like:

from matplotlib import plt
$\endgroup$
1
  • $\begingroup$ import matplotlib.pyplot as plt $\endgroup$
    – grofte
    Apr 8, 2018 at 12:22
0
$\begingroup$

The basic idea is to increase the default figure size in your plotting tool. You need to import matplotlib and set either default figure size or just the current figure size to a bigger one. Also, seaborn is built on top of matplotlib. You need to install and import matplitlib to make the best use of seaborn library.

$\endgroup$
0
$\begingroup$

This will also work and allows for scale to be parameterized. Figure size can even be adjusted after plotting.

fig = plt.gcf()  # or by other means, like plt.subplots
figsize = fig.get_size_inches()
fig.set_size_inches(figsize * 1.5)  # scale current size by 1.5

fig.set_size_inches

fig.get_size_inches

$\endgroup$
0
$\begingroup$

import seaborn as sn
import matplotlib.pyplot as plt
%matplotlib inline
plt.figure(figsize=(10,7))
sn.heatmap(cm,annot=True)

You can increase Heatmap size by using plt.figure(figsize=(10,7))

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.