import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
## Import
df = pd.read_excel("text4.xlsx", sheet_name = "before_2019")
df2 = pd.read_excel("text4.xlsx", sheet_name = "after_2019")
# Read Data
d = df.corr()
d2 = df2.corr()
# Corr matrix
# Plot!
plt.figure(figsize= (10, 16))
plt.subplot(2,1,1)
sns.heatmap(d2,annot = True,vmax = 1,square = True,cmap = "Reds")
plt.xticks(rotation=38)
plt.title("National Cooperation Before 2019")
plt.subplot(2,1,2)
sns.heatmap(d,annot = True,vmax = 1,square = True,cmap = "Reds")
plt.xticks(rotation=38)
plt.title("National Cooperation After 2019")
plt.show()
导入的数据大概是这样的excel:
结果如下: