I'm trying to generate a heatmap showing the correlation between different stock prices before running through some ML for a project for a course I'm taking at work. The relevant code is shown below and a picture of the Pandas data frame with the data being run on is attached as well. There's no missing numbers in the dataframe either. When I run the code the plot simply doesn't load. It forever stays in limbo. I've tried to find other questions with the same problem but could not find any in that they had different errors such as not having plt.show().
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from statsmodels.stats.outliers_influence import variance_inflation_factor
data=pd.read_excel("Sto.xlsx") #read data in
data.set_index("Date", inplace= True)
sns.heatmap(data.corr(),  annot=True)
plt.show()


This code works completely fine with the below data in a Jupyter Notebook. I imagine the issue is with Spyder and has nothing to do with your data/Seaborn. To get it to work with spyder, you can also ty to add: %matplotlib inline into your code. Another StackOverflow user recently (~5 months ago) had a similar issue with plots not appearing when using Seaborn with Spyder and this solved for them (Seaborn Plot is not displaying):
data = pd.DataFrame({'QQQ': {0: 97.8, 1: 96.4, 2: 95.1, 3: 96.3, 4: 98.2},
     'TSLA': {0: 43.9, 1: 42.0, 2: 42.26, 3: 42.19, 4: 42.12},
     'VIX': {0: 16903, 1: 16821, 2: 18470, 3: 19872, 4: 20120},
     'SPY': {0: 183.5, 1: 180.3, 2: 178.5, 3: 180.7, 4: 183.9},
     'MSFT': {0: 41.5, 1: 41.2, 2: 40.6, 3: 41.1, 4: 42.3}})
data
    QQQ     TSLA    VIX     SPY     MSFT
0   97.8    43.90   16903   183.5   41.5
1   96.4    42.00   16821   180.3   41.2
2   95.1    42.26   18470   178.5   40.6
3   96.3    42.19   19872   180.7   41.1
4   98.2    42.12   20120   183.9   42.3
import seaborn as sns
import matplotlib.pyplot as plt
data = df.corr()
sns.heatmap(data.corr(), annot=True)
plt.show()

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With