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

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

问题描述

我设法绘制了我的数据并想为其添加背景图像(地图).数据由 long/lat 值绘制,我也有图像三个角(左上角、右上角和左下角)的 long/lat 值.

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=[horizo​​ntal_min,horizo​​ntal_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天全站免登陆