0

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?

user18334254
  • 227
  • 1
  • 11

2 Answers2

2

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()
speeder1987
  • 307
  • 2
  • 11
  • I still dont see the map. I get the below: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. plt.show() – user18334254 Apr 13 '22 at 13:38
  • Weird, this works for me. How are you running your python script, are you using any kind of IDE or jupyter notebook – speeder1987 Apr 13 '22 at 13:48
  • There is some more information which looks relevant to you here: https://stackoverflow.com/questions/56656777/userwarning-matplotlib-is-currently-using-agg-which-is-a-non-gui-backend-so – speeder1987 Apr 13 '22 at 13:51
  • I am using Jupyter notebook – user18334254 Apr 13 '22 at 13:55
0

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.