【问题标题】:Defining longitudinal extent for mercator projection on cartopy为 cartopy 上的墨卡托投影定义纵向范围
【发布时间】:2017-04-27 02:14:03
【问题描述】:

我正在尝试绘制一些以矩阵形式存在的数据,例如温度。这些数据是区域性的,所以我不需要全球地图。

我有:

  1. 数据矩阵 (mxn)
  2. 定义纬度 (mx1) 和经度 (nx1) 的向量

我想使用带有墨卡托投影的 cartopy 来绘制它。然而,墨卡托只允许我定义最小和最大纬度,而不是最小和最大经度。这最终给了我一大片土地。

Mercator(central_longitude=103.0,min_latitude=gridlat[0],max_latitude=gridlat[-1])

我将如何设置沿海地图的最小和最大经度? 最终,我只想绘制我的数据,并在其上覆盖国家边界,就像使用 ncview 的样子一样。

【问题讨论】:

    标签: python matplotlib jupyter-notebook cartopy


    【解决方案1】:

    选择投影时通常不会设置地图的范围,稍后可以使用您创建的坐标区的set_extent 方法进行设置。实际上,cartopy 中的默认行为是将范围与绘制的数据相匹配,因此您想要的应该是使用普通墨卡托投影绘制图时发生的情况。以下是在地理坐标中显式设置范围的示例:

    import cartopy.crs as ccrs
    import matplotlib.pyplot as plt
    
    # Create Mercator projection with dateline in the middle:
    ax = plt.axes(projection=ccrs.Mercator(central_longitude=180))
    # Draw coastlines so we know where we are:
    ax.coastlines()
    # Set the map extent, making sure to specify the correct coordinate system
    # for geographical coordinates:
    ax.set_extent([90, 270, -40, 40], crs=ccrs.PlateCarree())
    plt.show()
    

    【讨论】:

    • 为什么要为 ax.set_extent ccrs.PlateCaree() 定义投影?应该是墨卡托吗?
    • 不,它应该是您提供数字范围的坐标系。在这种情况下,我想以纬度/经度坐标指定地图范围,因此PlateCarree 是合适的选择。如果我使用Mercator,我必须在原生坐标中为墨卡托投影指定范围。
    • @user2118915 如果对您有用,请“接受”答案。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-06
    • 1970-01-01
    • 2019-10-03
    相关资源
    最近更新 更多