How can I remove the frame of subplots from behind colour bars?

Viewed 22

I have different subplots sharing x axis. I have already set spines off for all the plots, but when I draw some bars using axvspan the 'ghost' of the plots' spines appear behing the coloured areas.

Anyone would like to suggest a solution to get rid the bars of the 'ghost lines'?

Thanks in advance

fig, (ax1, ax2, ax3, ax4, ax5, ax6, ax7) = plt.subplots(7, sharex=True,subplot_kw={'clip_on':False})
fig.subplots_adjust(hspace=0)


axes = [ax1, ax2, ax3, ax4, ax5, ax6, ax7]

for ax in axes:
    ax.spines['top'].set_visible(False)
    ax.spines['right'].set_visible(False)
    ax.spines['bottom'].set_visible(False)
    ax.spines['left'].set_visible(False)

ax1.plot(data1['age'], data1['Pb'], linewidth=0.8, c='black')
ax1.set_ylabel('Pb',c='black')
ax1.spines['left'].set_visible(True)
ax1.spines['left'].set_bounds(75, 25)
ax1.tick_params(labelbottom=False, bottom=False)
ax1.tick_params(axis='y', color='black', labelcolor='black')
...
for ax in axes:
     ax.axvspan(7600, 7500, alpha=0.2, color='red')
     ax.axvspan(7500, 7200, alpha=0.2, color='blue')
     ax.axvspan(7200, 7000, alpha=0.2, color='red')
     ax.axvspan(7000, 6600, alpha=0.2, color='blue')
     ax.axvspan(6600, 6300, alpha=0.2, color='red')
     ax.axvspan(6300, 6000, alpha=0.2, color='blue')
     ax.axvspan(6000, 5800, alpha=0.2, color='red')
     ax.axvspan(2000, 0, alpha=0.2, color='grey')

plt.xlabel('age bp')
plt.show()

grey, red and blue bars show the spines of the plots

0 Answers
Related