user18334254
user18334254

Reputation: 237

correlation heatmap in python

sounds like a simple enough task, but it is not working and I am not sure what I am doing wrong. I am trying to create a correlation heatmap. I use the code below:

sns.heatmap(df.corr(method='pearson', min_periods=1));

and simply nothing happens. when I then do the below:

hmap = sns.heatmap(df.corr(method='pearson', min_periods=1));
hmap

I get the output as:

<AxesSubplot:title={'center':'Triangle Correlation Heatmap'}>

can someone please help me understand this?

Upvotes: 0

Views: 2236

Answers (2)

Enric Grau-Luque
Enric Grau-Luque

Reputation: 124

You can use spectrapepper for this:

import spectrapepper as spep

# load sample data from the library
data = spep.load_params()

# labels
labels = ['T', 'A1', 'A2', 'A3', 'A4', 'A5', 'S1', 'R1', 'R2', 'ETA', 'FF', 'JSC', 'ISC', 'VOC']

# plot spearman
spep.spearman(data, labels)

# plot person
spep.pearson(data, labels)

The above is extracted for the documentation of the library. These functions automatically plot the heatmap and also return it in the form of a list for you to use the data after if you do:

heatmap = spep.spearman(data, labels)

You can print out the variable data to see what is the accepted format.

Upvotes: 0

speeder1987
speeder1987

Reputation: 307

You will need to use the plt.show() method to display the plot. Try integrating the code below:

import matplotlib.pyplot as plt
import seaborn as sns

sns.heatmap(df.corr(method='pearson', min_periods=1))
plt.show()

Upvotes: 2

Related Questions