[英]How to add Vertical Line into Seaborn Heatmap
如何在 searborn 热图中添加垂直线。 我做了以下方式,没有出现任何线条。 虽然没有错误。 我想知道这些线条是否被热图颜色覆盖? 有什么建议么? 谢谢
fig,ax=plt.subplots(1,1,figsize=(30,15))
g=sns.heatmap(df,cmap='coolwarm', robust=robust_colorbarrange,yticklabels=yticklabels,xticklabels=xticklabels,annot=False, \
cbar_kws={'fraction':0.02, "shrink": 1.0,'pad':0.01},vmin=colorbar_min, vmax=colorbar_max, ax=ax)
for datestr in CycleDates:
date=datetime.strptime(datestr,'%Y-%m-%d %H:%M')
ax.axvline(date,color='k',linestyle='-')
我找到了一个解决方案,包括覆盖matplotlib.Axe
,然后覆盖 plot 行:
fig, ax = plt.subplots(1, 1, figsize=(30, 15))
ax = sns.heatmap(df, ax=ax, **kwargs)
# create 2nd axis
ax2 = ax.twinx()
ax2.set_ylim(df.index.min(), df.index.max())
# and hide it
ax2.get_yaxis().set_visible(False)
ax2.grid(False)
# loop to create a line for each date as request by OP
i = 0
for datestr in CycleDates, :
date=datetime.strptime(datestr,'%Y-%m-%d %H:%M')
ax.axvline(date,color='k',linestyle='-')
ax2.vlines(date, i,i+1, color='k', linestyles='dashed')
我没有用 OP 代码检查这个答案,因为它不是一个独立的例子。 但是,我将该解决方案应用于我的一个问题并且它有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.