简体   繁体   中英

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. Any idea on how to do that? I have been trying with center but without success. 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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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