【问题标题】:Set plt.colorbar range with python/cartopy使用 python/cartopy 设置 plt.colorbar 范围
【发布时间】:2021-12-05 07:45:05
【问题描述】:

您好,我这里有这段代码,我用它来绘制气溶胶的气候图。

import matplotlib.pyplot as plt
from netCDF4 import Dataset as netcdf_dataset
import numpy as np

from cartopy import config
import cartopy.crs as ccrs
import cartopy.feature as cfeature

AODs_Season = netcdf_dataset('/home/vescovint/Documents/AOD_0219_DJF.nc')
lats = AODs_Season.variables['lat'][:]
lons = AODs_Season.variables['lon'][:]
AODS = AODs_Season.variables['AOD_550_Dark_Target_Deep_Blue_Combined_Mean_Mean'][0, :, :]

ax = plt.axes(projection=ccrs.PlateCarree())


plt.contourf(lons, lats, AODS, 60, transform=ccrs.PlateCarree(), cmap='YlOrRd')
plt.colorbar(shrink=0.55)
plt.gcf().set_size_inches(15, 11)
ax.coastlines()

plt.savefig('/home/vescovint/Documents/AOD_Maps/DJF2002')

我的问题是,我所有的地图在颜色条上都有不同的值范围,从 0 到 5,我会将其设置为 min = 0 和 max = 3。

我想不通,如果有人可以帮助我,我将不胜感激。

托马斯

【问题讨论】:

    标签: python range maps colorbar


    【解决方案1】:

    您可以使用 pyplot 中的 clim() 方法。例如:

    plt.clim(0,3) 
    

    设置绘图的颜色范围(参见doc

    【讨论】:

    • 我的问题不是很清楚对不起。 plt.clim() 只是更改颜色条的颜色范围,在我的情况下,我想更改最大值(标签给出的值),所以我的所有地图都将低于 0 到 2 的值范围。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-12
    • 2011-01-10
    • 1970-01-01
    • 1970-01-01
    • 2014-03-27
    • 2017-03-01
    相关资源
    最近更新 更多