如何在matplotlib.pyplot.imshow中使用“范围" [英] how to use 'extent' in matplotlib.pyplot.imshow

查看:340
本文介绍了如何在matplotlib.pyplot.imshow中使用“范围"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设法绘制了数据,并想为其添加背景图像(地图). 数据是按经/纬度值绘制的,我也具有图像的三个角(左上,右上和左下)的经/纬度值.

I managed to plot my data and would like to add a background image (map) to it. Data is plotted by the long/lat values and I have the long/lat values for the image's three corners (top left, top right and bottom left) too.

我试图弄清楚如何在imshow中使用'extent'选项.但是,我发现的示例并未说明如何为每个角指定x和y(在我的情况下,我具有三个角的信息).

I am trying to figure out how to use 'extent' option with imshow. However, the examples I found don't explain how to assign x and y for each corner ( in my case I have the information for three corners).

将图像添加到绘图中时,如何为图像分配三个角的位置?

How can I assign the location of three corners for the image when adding it to the plot?

谢谢

推荐答案

在当前轴的坐标中指定要粘贴图像的矩形的角

范围定义了左右限制以及上下限制.它需要四个值,如下所示: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应该相同,并且这些对中的值可以互换.

Assuming you have longitude along the horizontal axis, then use extent=[longitude_top_left,longitude_top_right,latitude_bottom_left,latitude_top_left]. longitude_top_left and longitude_bottom_left should be the same, latitude_top_left and latitude_top_right should be the same, and the values within these pairs are interchangeable.

如果图像的第一个元素应绘制在左下方,则也应使用origin='lower' imshow选项,否则,您需要使用'upper'默认值.

If your first element of your image should be plotted in the lower left, then use the origin='lower' imshow option as well, otherwise the 'upper' default is what you want.

这篇关于如何在matplotlib.pyplot.imshow中使用“范围"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆