how to use ‘extent’ in matplotlib.pyplot.imshow

Specify, in the coordinates of your current axis, the corners of the rectangle that you want the image to be pasted over

Extent defines the left and right limits, and the bottom and top limits. It takes four values like so: extent=[horizontal_min,horizontal_max,vertical_min,vertical_max].

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.

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.

Leave a Comment