python - Matplotlib imshow 偏移量以匹配轴?

标签 python numpy matplotlib gis coordinate-systems

我正在使用 matplotlib.pyplot.scatter 绘制一组 UTM 坐标。我还有一张背景航拍照片,我知道它与图的范围完全吻合。当我绘制数据并设置轴时,我可以正确显示散点图。如果我使用 imshow 绘制航空照片,它会使用像素数作为轴位置。我需要将图像(numpy 数组)移动到正确的 UTM 位置。有任何想法吗?我对 matplotlib 和 numpy 还很陌生。

例如:我知道图像的左上角(imshow坐标:0,0)有UTM坐标(269658.4, 538318.2)。我如何告诉 imshow 同样的事情?

我还应该说,我调查了 Basemap,但它似乎还没有完全支持 UTM。我的学习区域很小。

最佳答案

您需要为 imshow 使用 extent 关键字参数。

举个简单的例子:

import numpy as np
import matplotlib.pyplot as plt

# Random points between 50000 and 51000
x, y = 1000 * np.random.random((2, 10)) + 50000

# A 10x10 "image"...
image = np.arange(100).reshape((10,10))

# In a lot of cases, image data will be "flipped" vertically, so you may need 
# use the `origin` kwarg, as well (or just swap the ymin and ymax ordering).
plt.imshow(image, extent=[x.min(), x.max(), y.min(), y.max()])
plt.plot(x, y, 'ro')

plt.show()

enter image description here

关于python - Matplotlib imshow 偏移量以匹配轴?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12324176/

相关文章:

python - 如何同时使用多个字符串文字

python - 在具有多索引的 pandas Dataframe 中,我如何按顺序过滤?

python - 将列表转换为数组时减少维度

python - 时间类型误差直方图

python - 可视化 ffmpeg 基准

python - 有没有办法添加命名空间前缀 setuptools 包发行版?

python - 在 python 中将列重复为行?

python - 基于每日时间序列数据框创建工作日/周末时间序列数据框

Python:如何以最简单的方式比较两个数组

python - Seaborn Jointplot 更改 Figsize