如何使我的Cartopy颜色条具有我设定的特定范围?

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

我正在比较各种任务,我希望颜色条有我设置的最大值和最小值。我不知道该如何做到这一点,对此有何帮助?任务本身将保持在一个范围内,但我想设置它,所以它很容易比较。有些任务是不同的,有些不是,所以我不希望计算机自动设置最大值和最小值。

enter image description here

crs_latlon = ccrs.PlateCarree()
def make_plot(projection_name, projection_crs):

    ax = plt.axes(projection=projection_crs)
    #ax.set_extent((-65.0, -58, 40, 47.7), crs=crs_latlon)
    ax.set_extent((-65.0, -62, 43, 45.5), crs=crs_latlon)

    #Add coastlines and meridians/parallels (Cartopy-specific).
    plt.gca().coastlines('10m')

    ax.gridlines(crs=crs_latlon, linestyle='-')
    # Add a title, legend, and display.
    ax.set_title(''.join(("Mission #13: Attenuation Coeffiecient - ",
                      projection_name)))

    cb = plt.scatter(avglonlist, avglatlist, c=klist, cmap=coolwarm)
    plt.colorbar(cb, cmap=coolwarm, orientation='vertical',ticklocation='auto')
    #plt.colorbar.ColorbarBase(ax=ax, cmap = coolwarm, orientation='vertical', ticklocation='auto',
     #                        norm=plt.colors.Normalize(vmin=0, vmax=1))
    iplt.show()

def main():
# Demonstrate with two different display projections.
    make_plot('Equidistant Cylindrical', ccrs.PlateCarree())
    graph_my_latandk(avglatlist,klist)

if __name__ == '__main__':
    main()
python matplotlib mapping matplotlib-basemap cartopy
2个回答
3
投票

我想你必须像这里一样创建你的own color bar

import matplotlib.pylab as plt
from matplotlib import colorbar, colors

fig = plt.figure(figsize=(8, 3))
ax = fig.add_axes([.05, .05, .05, .7]) # position of colorbar
cbar = colorbar.ColorbarBase(ax, cmap=plt.get_cmap('coolwarm'),
  norm=colors.Normalize(vmin=-.5, vmax=1.5)) # set min, max of colorbar
cbar.set_clim(-.5, .5) # set limits of color map
plt.show()

vmin, vmax允许设置colorbar的限制,但clim允许设置颜色映射的限制。


0
投票

如果您将vmin和vmax传递给散射,则可以设置散点图的颜色范围,并相应地设置颜色栏。

EG

cb = plt.scatter(avglonlist, avglatlist, c=klist, cmap=coolwarm, vmin=-4, vmax=2)
plt.colorbar(cb, cmap=coolwarm, orientation='vertical',ticklocation='auto')
© www.soinside.com 2019 - 2024. All rights reserved.