Cartopy 图 high/low 地图上的海平面压力
Cartopy plot high/low sea level pressure on map
我正在从底图迁移到 cartopy。我想做的一件事是在地图上绘制 high/low 压力,例如在底图中。此页面上有一个很好的示例说明如何执行此操作:https://matplotlib.org/basemap/users/examples.html ("Plot sea-level pressure weather map with labelled highs and lows")。我不打算从该站点复制和粘贴代码,但想知道如何在 cartopy 中执行相同的操作。我无法理解的主要事情是如何在 cartopy 中做 m.xmax and x > m.xmin and y < m.ymax and y > m.ymin
(我想象的某种矢量变换。
我仔细看了看,没有看到这个特定的例子被翻译成与 cartopy 兼容的东西。欢迎任何帮助!
为了使用 cartopy 编写等效程序,您需要能够翻译两个概念。首先是找到投影的范围,这可以通过 GeoAxes
:
的 get_extent()
方法来完成
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
my_proj = ccrs.Miller(central_longitude=180)
ax = plt.axes(projection=my_proj)
xmin, xmax, ymin, ymax = ax.get_extent()
您还需要将坐标点从地理坐标转换为投影坐标,这是坐标参考系统实例的transform_points()
方法的功能:
import numpy as np
lons2d, lats2d = np.meshgrid(lons, lats) # lons lats are in degrees
transformed = my_proj.transform_points(ccrs.Geodetic(), lons2d, lats2d)
x = transformed[..., 0] # lons in projection coordinates
y = transformed[..., 1] # lats in projection coordinates
现在您可以使用与底图示例中相同的技术来过滤和绘制点,其中您使用 xmin
等代替 m.xmin
当然还有其他方法可以做到这一点,相对于底图示例而言,这些方法各有利弊。如果你想出了一些好东西,你可以把它贡献给 Cartopy 画廊。
我正在从底图迁移到 cartopy。我想做的一件事是在地图上绘制 high/low 压力,例如在底图中。此页面上有一个很好的示例说明如何执行此操作:https://matplotlib.org/basemap/users/examples.html ("Plot sea-level pressure weather map with labelled highs and lows")。我不打算从该站点复制和粘贴代码,但想知道如何在 cartopy 中执行相同的操作。我无法理解的主要事情是如何在 cartopy 中做 m.xmax and x > m.xmin and y < m.ymax and y > m.ymin
(我想象的某种矢量变换。
我仔细看了看,没有看到这个特定的例子被翻译成与 cartopy 兼容的东西。欢迎任何帮助!
为了使用 cartopy 编写等效程序,您需要能够翻译两个概念。首先是找到投影的范围,这可以通过 GeoAxes
:
get_extent()
方法来完成
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
my_proj = ccrs.Miller(central_longitude=180)
ax = plt.axes(projection=my_proj)
xmin, xmax, ymin, ymax = ax.get_extent()
您还需要将坐标点从地理坐标转换为投影坐标,这是坐标参考系统实例的transform_points()
方法的功能:
import numpy as np
lons2d, lats2d = np.meshgrid(lons, lats) # lons lats are in degrees
transformed = my_proj.transform_points(ccrs.Geodetic(), lons2d, lats2d)
x = transformed[..., 0] # lons in projection coordinates
y = transformed[..., 1] # lats in projection coordinates
现在您可以使用与底图示例中相同的技术来过滤和绘制点,其中您使用 xmin
等代替 m.xmin
当然还有其他方法可以做到这一点,相对于底图示例而言,这些方法各有利弊。如果你想出了一些好东西,你可以把它贡献给 Cartopy 画廊。