# Python：在Seaborn中更改/自定义颜色图

#### Python: Change/customise colour maps in Seaborn

``````sns.heatmap(heat_map, annot=True, fmt=".2g", cmap="YlOrRd", linewidths=0.5,
linecolor='black', xticklabels=xticks, yticklabels=yticks
)
``````

**由于工作量有限，我只能张贴什么代码/示例。

1 个回复

``````import numpy as np; np.random.seed(42)
import matplotlib.pyplot as plt
import matplotlib.colors
import seaborn as sns

# some data
a = np.array([0.,0.002,.005,.0099,0.01,.0101,.02,.04,.24,.42,.62,0.95,.999,1.])
data = np.random.choice(a, size=(12,12))

# create colormap. We take 101 values equally spaced between 0 and 1
# hence the first value 0, second value 0.01
c = np.linspace(0,1,101)
# For those values we store the colors from the "YlOrRd" map in an array
colors = plt.get_cmap("YlOrRd",101)(c)
# We replace the first row of that array, by white
colors[0,:] = np.array([1,1,1,1])
# We create a new colormap with the colors
cmap = matplotlib.colors.ListedColormap(colors)

# Plot the heatmap. The format is set to 4 decimal places
# to be able to disingush specifically the values ,.0099, .0100, .0101,
sns.heatmap(data, annot=True, fmt=".4f", cmap=cmap, vmin=0, vmax=1,
linewidths=0.5,  linecolor='black')
plt.show()
``````

1 seaborn/matplotlib 自定义颜色图

3 Python中的自定义颜色图

2015-09-11 13:17:22 4 9342   colormap
5 从Seaborn的两个不同数据框中读取时自定义条形图的颜色

2018-06-21 02:13:41 1 276   seaborn
6 python 中颜色矢量的自定义颜色图

7 在seaborn中自定义相关热图

8 在Seaborn中添加自定义条形图注释

2020-08-10 19:43:47 0 46   seaborn
9 seaborn 中的 Facetgrid 在图例中自定义颜色

2020-04-16 13:21:20 1 594   seaborn
10 自定义注释Seaborn热图

2015-10-15 20:36:01 3 21562   seaborn