对于发散值,默认情况下,seaborn似乎在暖色调(橙色)中显示大数字,在冷色调(蓝色)中显示小数字。
如果我需要将颜色切换到相反的颜色,要显示蓝色和橙色的大数字,怎么办?
我已经搜索过,但还没找到方法。
sns.heatmap(flights, center=flights.loc["January", 1955])
答案 0 :(得分:7)
您可以通过在名称后添加_r
来反转所有matplotlib色彩映射,即plt.cm.coolwarm
vs plt.cm.coolwarm_r
。
我相信seaborn默认使用cubehelix色彩映射。
所以你要这样做:
from matplotlib import pyplot
import seaborn as sns
colormap = pyplot.cm.cubehelix_r
flights = sns.load_dataset('flights').pivot("month", "year", "passengers")
sns.heatmap(flights, cmap=colormap)
答案 1 :(得分:0)
无需为热图构建单独的反向函数。
只需使用 cmap ='magma_r'。默认设置为“岩浆”,因此我们只需在“ _r”后面附加即可。