我设法绘制了我的数据,并想在其中添加一个背景图像(地图)。数据是通过经度/纬度值绘制的,我也有图像三个角(左上角、右上角和左下角)的经度/纬度值。
我正在尝试弄清楚如何在imshow中使用“扩展”选项。然而,我发现的示例并没有解释如何为每个角分配x和y(在我的例子中,我有三个角的信息)。
如何在将图像添加到绘图时为其分配三个角的位置?
谢谢
发布于 2011-08-10 01:38:14
在当前轴的坐标中,指定要粘贴图像的矩形的角
范围定义左侧和右侧限制,以及底部和顶部限制。它采用如下四个值:extent=[horizontal_min,horizontal_max,vertical_min,vertical_max]。
假设您具有沿水平轴的经度,则使用extent=[longitude_top_left,longitude_top_right,latitude_bottom_left,latitude_top_left]。longitude_top_left和longitude_bottom_left应该相同,latitude_top_left和latitude_top_right应该相同,并且这些对中的值可以互换。
如果您的图像的第一个元素应该绘制在左下角,那么也可以使用origin='lower' imshow选项,否则‘上方’默认值就是您想要的。
发布于 2012-09-20 01:54:03
下面是一个基于http://matplotlib.org/examples/pylab_examples/image_demo3.html的示例,展示了扩展的用法。
#!/usr/bin/env python
from pylab import *
try:
from PIL import Image
except ImportError, exc:
raise SystemExit("PIL must be installed to run this example")
import matplotlib.cbook as cbook
datafile = cbook.get_sample_data('ada.png')
h = Image.open(datafile)
dpi = rcParams['figure.dpi']
figsize = h.size[0]/dpi, h.size[1]/dpi
figure(figsize=figsize)
ax = axes([0,0,1,1], frameon=False)
ax.set_axis_off()
ax.set_xlim(0,2)
ax.set_ylim(0,2)
im = imshow(h, origin='upper',extent=[-2,4,-2,4]) # axes zoom in on portion of image
im2 = imshow(h, origin='upper',extent=[0,.5,0,.5]) # image is a small inset on axes
show()如果您不设置轴限制,它们将成为您的范围&然后似乎没有任何效果。

https://stackoverflow.com/questions/6999621
复制相似问题