1

A very similar question, solved the same way: how to use 'extent' in matplotlib.pyplot.imshow


I have a list of geographical coordinates (a "tracklog") that describe a geographical trajectory. Also, I have the means of obtaining an image spanning the tracklog coverage, where I know the "geographical coordinates" of the corners of the image.

My plot currently looks like this (notice the ticks - x=longitudes, y=latitudes, in UTM, WGS84):

enter image description here

Then suppose I know the corner coordinates of the following image (or a version of it without the blue track), and would like to plot it SO THAT IT FITS THE COORDINATE SYSTEM of the plot.

enter image description here

How would I do it?

(as a side note, in case that matters, I plan to use tiles)


As per the comment of Joe Kington (waiting for his actual answer so that I can accept it), the following code works as expected, giving a pannable and zoomable fixed-aspect "georeferenced" tile over which I am able to plot tracklogs:

import matplotlib.pyplot as plt
import Image
import numpy

imarray = numpy.asarray(Image.open('map.jpg'))

plt.plot([0,1], [0,1], 'o', c='red', ms=20)  ## some reference circles for debugging
plt.imshow(imarray, extent=[0,1,0,1])   ## some random map whose corners have known coordinates
plt.axis('equal')
plt.show()

enter image description here

Community
  • 1
  • 1
heltonbiker
  • 26,657
  • 28
  • 137
  • 252
  • Are you asking how to project it (you mention UTM and geographic coordinates) or just how to plot an image with specified extents? (If it's the latter, just use the `extents` kwarg to `imshow`.) – Joe Kington Sep 11 '12 at 01:55
  • @JoeKington I'd like to just plot, since the image is already "projected" (its grid is the same as the plot grid). I'm take a look at `extents`, but if you could post a working answer I'd gladly accept it! – heltonbiker Sep 11 '12 at 13:38
  • From what I see, `extents` adjusts the axes to the image, and not the opposite. I'm trying something with OffsetImage as suggested here: http://stackoverflow.com/a/4860777/401828 – heltonbiker Sep 11 '12 at 13:50
  • No, it just calls `axis(image)` after plotting, which makes it appear that way. Just specify `aspect = "auto"` to imshow and either plot the image first, or reset thelimits of the axes after plotting the image. (it's easiest to just plot it first). I'm posing this from a phone, or else I'd give a full example. Offset image is for when you want the size of the image to be in display coordinates. hope that helps a bit, anyway! – Joe Kington Sep 11 '12 at 16:21
  • @JoeKington It helps, but I'll need time to fully grasp it too. Thanks for now! – heltonbiker Sep 11 '12 at 18:22

1 Answers1

0

There is really not much of an answer here, but if you are using matplotlib, and you geos-tuff, take a look at matplotlib.basemap.
By default all operations are done on UTM maps, but you can choose your own projection. Take also a look on the list of good tutorials in http://www.geophysique.be, for example.

oz123
  • 27,559
  • 27
  • 125
  • 187