如何使用 Seaborn 在特定阈值下创建带有黑色的自定义颜色图

How to create a custom colormap with black under a specific threshold with Seaborn

我的速度值范围从 0 到 4000 (m/year),我想要一个像照片示例中的颜色图,但低于 1000 的所有东西都是黑色的。关于如何做到这一点的任何想法?我一直在尝试 center 但没有成功。我使用的代码是:

# Plot Hovmoller diagram
# turn the axis label
df_velocity = df_velocity.sort_index()
df_velocity2 = df_velocity.fillna(0)  # I replace all my nans by zeros otherwise there are too many holes in my plot
plt.figure(figsize=(15,15))
ax = sns.heatmap(df_velocity2,vmin=0, vmax=4000)#,center=1000)

尝试将 cmap.set_under('black') 设置为 vmin=1000,例如:

data = np.linspace(0, 60)[:, None] * np.linspace(0, 60)

cmap = matplotlib.cm.get_cmap('viridis').copy()
cmap.set_under('black')

sns.heatmap(data, vmin=1000, vmax=4000, cmap=cmap, cbar_kws=dict(extend='min', extendrect=True))