在热图中每第 7 列后插入一行

Insert line in heatmap after every 7th column

有人可以帮助我如何在我的情节中的每 7 列之后添加一条垂直线吗?

所以我想在新的 M1 开始后在这里有一条粗垂直线..有人有想法吗? 我的代码是:

piv = pd.pivot_table(df2, values="Corr",index=["GABA Receptor"], columns=["Experiment"], fill_value=0)
ax= sns.heatmap(piv, xticklabels=True, vmin=0, vmax=0.5)
# fix for mpl bug that cuts off top/bottom of seaborn viz
b, t = plt.ylim() # discover the values for bottom and top
b += 0.5 # Add 0.5 to the bottom
t -= 0.5 # Subtract 0.5 from the top
plt.ylim(b, t) # update the ylim(bottom, top) values
plt.show() # ta-da!
plt.title('Chronification Group')
plt.xticks(fontsize=10, rotation=90)
# fix for mpl bug that cuts off top/bottom of seaborn viz
b, t = plt.ylim() # discover the values for bottom and top
b += 0.5 # Add 0.5 to the bottom
t -= 0.5 # Subtract 0.5 from the top
plt.ylim(b, t)

您可以使用 plt.vlines() (documentation) 来完成,您可以在其中指定垂直线的 xyminymax
以上面的代码为例:

import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt

corr = np.random.rand(11, 28)

fig, ax = plt.subplots(figsize = (12, 6))

sns.heatmap(ax = ax,
            data = corr)

b, t = plt.ylim()
ax.vlines(x = 7, ymin = b, ymax = t, colors = 'blue', lw = 5)

plt.show()

给出了这个热图: