如何仅使用PCOLORMESH绘制分类数据集的特定值

发布于 2025-02-08 20:57:14 字数 975 浏览 1 评论 0原文

我试图绘制分类降水类型,并且我想用一个结肠座,因为阵列包括-0.99(无爆炸)或0.99(stead)。我想知道如何仅在数据等于0.99时绘制。目前,这是我正在尝试的代码,它只是绘制了我的整个地图粉红色。有更好的方法吗?

import matplotlib as mpl
from matplotlib import colors
import cartopy.crs as ccrs
import matplotlib.pyplot as plt

proj = ccrs.LambertConformal(central_longitude=cLon, 
central_latitude=cLat)

fig = plt.figure(figsize=(12,12),dpi=100) # Increase the dots per inch from default 100 to make plot easier to read
ax = fig.add_subplot(1,1,1,projection=proj)
ax.set_extent ([lonW,lonE,latS,latN])

ptype_colors_fzra = ['deeppink']
cmap_ptype_ext_fzra = mpl.colors.ListedColormap(ptype_colors_fzra)
norm_ptype_ext_fzra = mpl.colors.BoundaryNorm([0.98,1],ncolors = len(ptype_colors_fzra))

ax.contourf(lons, lats, cfzra, cmap = cmap_ptype_ext_fzra, norm = norm_ptype_ext_fzra, 
transform = ccrs.PlateCarree(), zorder = 2)

This is what ends up plotting

I am trying to plot categorial precipitation type and I have a colormap I want to use as the array either includes -0.99 (no precip) or 0.99 (precip). I want to know how to only plot when the data is equal to 0.99. Currently this is the code I am trying and it is just plotting my whole map pink. Is there a better way to do this?

import matplotlib as mpl
from matplotlib import colors
import cartopy.crs as ccrs
import matplotlib.pyplot as plt

proj = ccrs.LambertConformal(central_longitude=cLon, 
central_latitude=cLat)

fig = plt.figure(figsize=(12,12),dpi=100) # Increase the dots per inch from default 100 to make plot easier to read
ax = fig.add_subplot(1,1,1,projection=proj)
ax.set_extent ([lonW,lonE,latS,latN])

ptype_colors_fzra = ['deeppink']
cmap_ptype_ext_fzra = mpl.colors.ListedColormap(ptype_colors_fzra)
norm_ptype_ext_fzra = mpl.colors.BoundaryNorm([0.98,1],ncolors = len(ptype_colors_fzra))

ax.contourf(lons, lats, cfzra, cmap = cmap_ptype_ext_fzra, norm = norm_ptype_ext_fzra, 
transform = ccrs.PlateCarree(), zorder = 2)

This is what ends up plotting

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文