【问题标题】:How to create a custom colormap with black under a specific threshold with Seaborn如何使用 Seaborn 在特定阈值下创建带有黑色的自定义颜色图
【发布时间】:2021-07-19 10:01:23
【问题描述】:

我的速度值范围从 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)

【问题讨论】:

    标签: python pandas plot seaborn heatmap


    【解决方案1】:

    尝试将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))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-28
      • 2020-10-21
      • 2020-07-28
      • 2015-08-05
      • 2020-06-21
      • 1970-01-01
      • 2021-04-02
      • 1970-01-01
      相关资源
      最近更新 更多