簡體   English   中英

如何使用 Seaborn 在特定閾值下創建自定義顏色圖

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

我的速度值范圍從 0 到 4000(米/年),我想要一個像照片示例中那樣的顏色圖,但 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)

在此處輸入圖像描述

嘗試使用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