【问题标题】:Setting axis extent on Cartopy UTM projection在 Cartopy UTM 投影上设置轴范围
【发布时间】:2020-08-23 07:42:51
【问题描述】:

我想使用 Matplotlib (v3.1.3) 和 Cartopy (v0.17.0) 绘制一组 UTM 坐标,然后手动设置轴的范围。通常我可以使用axis.set_extent((left, right, bottom, top)) 执行此操作,但是当我尝试使用 UTM 坐标执行此操作时,我收到一条错误消息,声称我的坐标超出了允许的范围。当我从字面上复制并插入当前轴范围(使用axis.get_extent())时,也会发生这种情况。

请参阅以下最小示例:

import cartopy
import cartopy.crs as ccrs
import numpy as np
import matplotlib.pyplot as plt

# Some random UTM coordinates
UTM = np.array([
    [328224.965, 4407328.289],
    [328290.249, 4407612.599],
    [328674.439, 4408309.066],
    [327977.178, 4407603.320],
    [328542.037, 4408510.581]
]).T

# Split into east and north components
east, north = UTM

# Create a canvas with UTM projection
fig = plt.figure()
ax = fig.add_subplot(111, projection=ccrs.UTM(zone="11S"))

# Plot coordinates
ax.scatter(east, north)

# Get the extent of the axis
extent = ax.get_extent()
# Attempt to set the axis extent
ax.set_extent(extent)

plt.show()

这会引发以下异常:

ValueError: Failed to determine the required bounds in projection coordinates. Check that the values provided are within the valid range (x_limits=[-250000.0, 1250000.0], y_limits=[-10000000.0, 25000000.0]).

这是一个错误还是我做错了什么?还有其他设置轴范围的方法吗?

【问题讨论】:

    标签: python matplotlib cartopy


    【解决方案1】:

    代码行:

    ax.set_extent(extent)
    

    有一个选项crs=None,这意味着将ccrs.PlateCarree() 作为默认值。这意味着在代码中的extent 中需要以经度和纬度为单位的值。

    要正确,必须指定正确的crs:-

    ax.set_extent(extent, crs=ccrs.UTM(zone="11S"))
    

    【讨论】:

      猜你喜欢
      • 2020-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-05
      • 2019-07-01
      • 1970-01-01
      相关资源
      最近更新 更多