带有 seaborn 的 subplot2grid 会覆盖相同的斧头

subplot2grid with seaborn overwrites same ax

指定我希望图表去向的坐标轴的正确方法是什么?

目前我正在尝试绘制不同的热图,每个热图都在不同的斧头中。但是当尝试这个时,它只是将 2 个图表绘制在另一个之上。

import seaborn as sns 
import matplotlib.pyplot as plt

fig3 = plt.figure(figsize=(12,10))

ax1     = plt.subplot2grid((11,2),(0,0), rowspan=3, colspan=1)
ax2     = plt.subplot2grid((11,2),(4,0), rowspan=3, colspan=1)

ax1 = sns.heatmap(dict_pivots['df_pivot_10_win_2_thres'], square=False, cmap="RdYlBu", 
                    linewidths=0.1, annot=True, annot_kws={"size":12})

ax2 = sns.heatmap(dict_pivots['df_pivot_5_win_2_thres'], square=False, cmap="RdYlBu", 
                    linewidths=0.1, annot=True, annot_kws={"size":12})

这是它的样子:

您只需将 Axes 对象传递给 heatmap 函数:

import seaborn as sns 
import matplotlib.pyplot as plt

fig3 = plt.figure(figsize=(12,10))

ax1 = plt.subplot2grid((11,2),(0,0), rowspan=3, colspan=1)
ax2 = plt.subplot2grid((11,2),(4,0), rowspan=3, colspan=1)

ax1 = sns.heatmap(dict_pivots['df_pivot_10_win_2_thres'],
                  square=False,  cmap="RdYlBu",
                  linewidths=0.1, annot=True,
                  annot_kws={"size":12},
                  ax=ax1)  # <-- here

ax2 = sns.heatmap(dict_pivots['df_pivot_5_win_2_thres'],
                  square=False,  cmap="RdYlBu",
                  linewidths=0.1, annot=True,
                  annot_kws={"size":12},
                  ax=ax2)  # <-- and here