簡體   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