matplotlib 在热图中每隔7列插入一行

63lcw9qa  于 2022-11-15  发布在  其他
关注(0)|答案(1)|浏览(123)

谁能帮我在我的绘图中每隔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)
v6ylcynt

v6ylcynt1#

您可以使用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()

这给出了热图:

相关问题