如何在seaborn热图中反转颜色标量

san*_*oku 3 python plot colors heatmap seaborn

对于不同的值,默认情况下,seaborn似乎在暖色调(橙色)中显示大数字,在冷色调(蓝色)中显示小数字.

如果我需要将颜色切换到相反的颜色,要显示蓝色和橙色的大数字,怎么办?

我搜索过但还没有找到方法.

sns.heatmap(flights, center=flights.loc["January", 1955])
Run Code Online (Sandbox Code Playgroud)

Pau*_*l H 7

您可以通过附加扭转所有matplotlib色彩映射表中_r的名称,即,plt.cm.coolwarmVS 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)
Run Code Online (Sandbox Code Playgroud)