Flodude
Flodude

Reputation: 275

Visualizing a huge correlation matrix in python

I have hundreds of features and I want to visualize their correlation in Python. But the code below does not display all feature captions in the chart. What solution do you suggest?

df = pd.read_csv('dataset.csv', sep=',')
sns.heatmap(df.corr())
plt.show()

enter image description here

Upvotes: 5

Views: 10120

Answers (1)

Frightera
Frightera

Reputation: 5079

Without figsize & dpi, seems so collapsed.

import seaborn as sns
sns.heatmap(df.corr(), annot = True, fmt = '.2f')

enter image description here

For to make it more readable, adjust figsize & dpi according to your needings. That's max dpi and figsize I can use for this example df otherwise it exceeds 2MB

import seaborn as sns

fig = plt.figure(figsize=(36,36), dpi = 480)
sns.heatmap(df.corr(), annot = True, fmt = '.2f')

enter image description here

Upvotes: 3

Related Questions