我正在从底图迁移到cartopy。我想做的一件事是在地图上绘制高/低压力,例如在底图中。在这个页面上有一个很好的例子,说明如何做到这一点:https://matplotlib.org/basemap/users/examples.html(“绘制标有高点和低点的海平面压力天气图”)。我不打算从这个网站复制和粘贴代码,但想知道如何在纸板上做同样的事情。我无法理解的主要问题是如何在纸板中进行m.xmax and x > m.xmin and y < m.ymax and y > m.ymin
(我想象的某种矢量变换。
我看起来很好看,看不出这个特殊的例子被翻译成与cartopy兼容的东西。欢迎任何帮助!
答案 0 :(得分:2)
为了使用cartopy编写等效程序,您需要能够翻译两个概念。第一个是查找投影的范围,可以使用get_extent()
的{{1}}方法完成:
GeoAxes
您还需要将坐标点从地理坐标转换为投影坐标,这是坐标参考系统实例的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
使用m.xmin
等。
当然有其他方法可以做到这一点,相对于底图示例有利有弊。如果你想出一些不错的东西,你可以将它贡献给Cartopy画廊。