颜色均匀分布的颜色条的数据不均匀(不规则)

问题描述 投票:1回答:1

我正在尝试创建具有13个级别的颜色栏,并使用中心值间隔为0的发散的RdBu_r颜色图。目前,我有an evenly spaced colorbar with values descending by 8 ranging from -48 to +48

[我想制作的是颜色间距均匀但颜色间距不均匀的色条,like this colorbar which I modified in photoshop, such that the values go from [-96.0, -72, -48, -24, -12, -6, 0, 6, 12, 24, 48, 72, 96]

我目前的尝试如下:

from cartopy import crs as ccrs;  import matplotlib.pyplot as plt

crs_new = ccrs.PlateCarree()

fig, axs = plt.subplots(subplot_kw={'projection': crs_new},figsize=(8, 6))

cmap = 'RdBu_r'  

uneven_levels = [-96.0, -72, -48, -24, -12, -6, 0, 6, 12, 24, 48, 72, 96]
vmin,vmax = -48,48
cs=plt.pcolormesh(lon,lat, data,cmap=cmap, transform=crs_new,vmin=vmin,vmax=vmax)
cbar=plt.colorbar(cs,boundaries= uneven_levels)

Which results in a colorbar with really dark ends and clearly uses linearly spaced coloring.

使用countourf和“ spacing =制服”无效。

使用“ colors.DivergingNorm(vmin = vmin,vcenter = 0,vmax = vmax)”无效。

我尝试使用]定义自己的颜色栏>

cmap = plt.get_cmap('RdBu_r')
colors = cmap(np.linspace(0, 1, len(uneven_levels)))

但不知道要使数据与这些级别相匹配,结果与图3相同,因此这也不起作用。

非常感谢您的帮助! :)

[我正在尝试创建一个具有13个级别的颜色条,并使用中心值间隔为0的发散的RdBu_r颜色图。目前,我有一个均匀间隔的颜色条,其值下降了8个范围...

python matplotlib colorbar
1个回答
0
投票
vmin, vmax = -48, 48的颜色很多的原因是-48会将48以下的所有值强制为最暗的蓝色,并将contourf以上的所有值强制为最暗的红色。
© www.soinside.com 2019 - 2024. All rights reserved.