簡體   English   中英

鏡像 Seaborn 熱圖的色標,包括 colors 和標簽

[英]Mirror the color scale of a Seaborn heatmap, both colors and labels

我有一個使用 Seaborn 模塊生成的熱圖,如下所示

由於表格中的值通常隨着與 MSL 的距離而增加(表格中的值增加),我想鏡像色階,使深藍色位於底部,對應的 label(12),和淺黃色在頂部,與 label (3)。

我只找到了一種反轉 colors 的方法,但隨后標簽仍然存在。 如何鏡像整個比例(colors 和標簽)?

謝謝!

顏色條軸上的invert_yaxis()反轉刻度標簽和顏色條( invert_xaxis()對水平顏色條執行相同的操作)。

Seaborn 的熱圖不會直接返回生成的顏色條的句柄。 它可以通過繪圖的ax獲得: cbar = ax.collections[0].colorbar

這是一個例子:

import seaborn as sns
import numpy as np
import matplotlib.pylab as plt

x, y = np.meshgrid(np.arange(20), np.arange(20))
arr = (x * y) % 10
ax = sns.heatmap(arr, annot=True, cbar=True)
cbar = ax.collections[0].colorbar
cbar.ax.invert_yaxis()
plt.show()

結果圖

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM