【发布时间】: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