简体   繁体   English

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

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

I have velocity values ranging from 0 to 4000 (m/year) and I would like a colormap like the one in the photo example, but with everything under 1000 being black.我的速度值范围从 0 到 4000(米/年),我想要一个像照片示例中那样的颜色图,但 1000 以下的所有内容都是黑色的。 Any idea on how to do that?关于如何做到这一点的任何想法? I have been trying with center but without success.我一直在尝试使用center ,但没有成功。 The code I use is:我使用的代码是:

# 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)

在此处输入图像描述

Try setting cmap.set_under('black') with vmin=1000 , eg:尝试使用vmin=1000设置cmap.set_under('black') ,例如:

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))

vmin=1000 与 set_under('k')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM