Insert line in heatmap after every 7th column

Question:

can someone help me how to add a veritcal line after every 7th column in my plot here?

enter image description here

So I want to have after the new M1 starts a thick vertical line here.. Has someone an idea?
My code is:

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)
Asked By: Anja

||

Answers:

You can do it with the plt.vlines() (documentation), where you specify the x, ymin and ymax of your vertical line.
Se the code above as an example:

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()

which gives this heatmap:

enter image description here

Answered By: Zephyr