2012-09-07 83 views
14

我正在绘制一堆使用matplotlib.pyplot.scatter的UTM坐标。我也有一张背景空中照片,我知道它完全符合图的范围。当我绘制数据并设置轴时,我可以正确显示散点图。如果使用imshow绘制空中照片,则使用像素编号作为轴位置。我需要将图像(numpy数组)转换为正确的UTM位置。有任何想法吗?我对matplotlib和numpy相当陌生。Matplotlib imshow偏移以匹配轴?

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

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

回答

18

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

作为一个简单的例子:

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

+0

谢谢!这正是我想要的!我不确定为什么我无法在API中找到该关键字。 –

+0

在各种matplotlib函数的关键字参数中很容易迷失方向。但是,在文档中,我保证! :)很高兴帮助,无论如何。 –