python - 如何让我的 Cartopy 颜色条具有我设置的特定范围?

标签 python matplotlib mapping matplotlib-basemap cartopy

我正在比较各种任务,我希望颜色条具有我设置的最大值和最小值。我不确定该怎么做,有什么帮助吗?任务本身会保持在一个范围内,但我想设置它,所以很容易比较。有些任务不同,有些则不同,所以我不希望计算机自动设置最大值和最小值。

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

最佳答案

我猜你必须创建你的 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 允许设置颜色条的限制,但是 clim 允许设置颜色图的限制。

关于python - 如何让我的 Cartopy 颜色条具有我设置的特定范围?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46027111/

相关文章:

python - 将值放在直方图的 bin 中心

python - 如何在没有 discord.py 的情况下获取用户在 discord 服务器中发送的消息数?

python - 重新分配字典值

python - 在 django 中使用 ImageField 加载具有模型的数据

python-2.7 - 在图例中使用不同的颜色和形状 [Seaborn,Python]

python - 在 Matplotlib 中保持绘图窗口打开

.net - 在 .NET 中显示 NOAA 图表

c# - C#中2个纬度/经度点之间的方向

c# - 确定一个点是沿着一条线还是非常接近的算法

python - 有没有办法只执行文档测试,而忽略打印函数调用?