繁体   English   中英

将 y 轴设置为 Seaborn 热图中的比例

[英]Set the y-axis to scale in a Seaborn heat map

我目前有一个数据框,df:

In  [1]: df
Out [1]:

   one        two
      1.5    11.22
        2    15.36
      2.5    11
      3.3    12.5
      3.5    14.78
        5    9
      6.2    26.14

我使用此代码获取热图:

In [2]:

plt.figure(figsize=(30, 7))
plt.title('Test')
ax = sns.heatmap(data=df, annot=True,)
plt.xlabel('Test')
ax.invert_yaxis()

value = 6
index = np.abs(df.index - value).argmin()
ax.axhline(index + .5, ls='--')
print(index)

Out [2]:

出 [2] 结果

相反,我正在寻找 y 轴来自动缩放和绘制 df[2] 值在全轴上各自的位置。 例如,在 3.5 和 5.0 之间应该有一个明显的空白空间,因为没有任何值 - 我希望 y 轴上的值与它们之间的值为 0。

这可以通过条形图轻松实现:

plt.bar(df['one'], df['two'], color=list('rgb'), width=0.2, alpha=0.4)

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM