Python 如何将热图与等高线图结合起来?

Python 如何将热图与等高线图结合起来?,python,pandas,matplotlib,seaborn,Python,Pandas,Matplotlib,Seaborn,我有两个类似的三维但独立的数据集(在不同的CSV文件中),其中α和δ是自变量,而φ(第一个数据集)或百分比值(第二个数据集)是因变量。数据集类似于数据透视表 我已经绘制了第一个数据集的热图: 现在我想添加第二个数据集的百分比值作为等高线。我在以下示例中手动完成了此操作: 如何使用Seaborn或Matplotlib实现这一点? 我目前的代码如下: import matplotlib.pyplot as plt import pandas as pd import seaborn as sns

我有两个类似的三维但独立的数据集(在不同的CSV文件中),其中α和δ是自变量,而φ(第一个数据集)或百分比值(第二个数据集)是因变量。数据集类似于数据透视表

我已经绘制了第一个数据集的热图:

现在我想添加第二个数据集的百分比值作为等高线。我在以下示例中手动完成了此操作:

如何使用Seaborn或Matplotlib实现这一点? 我目前的代码如下:

import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns; sns.set_theme()

df = pd.read_csv("data.csv", sep=";").transpose()
sns.heatmap(
    df,
    cmap="Reds",
    cbar_kws={"label": r'$\phi$'},
    vmin=0.0, vmax=1.2).invert_yaxis()
plt.xlabel(r'$\alpha$', fontsize=20)
plt.ylabel(r'$\delta$', fontsize=20)
plt.tight_layout()
plt.show()

尝试使用
轮廓

x,y = np.meshgrid(np.arange(df2.shape[0])+0.5, 
                  np.arange(df2.shape[1])+0.5, 
                  indexing='ij'
                 )

ax=sns.heatmap(df1)
ax.contour(x,y, df2, levels=[40,80,100])