I have a set of x,y map coordinates that I want plotted on an background image of the map.
I use the following code to display my map:
import matplotlib.pyplot as plt
im=plt.imread('map.gif')
implot=plt.imshow(im,origin='lower')
Now the ranges for the x and y axes are the pixel values of the image. In my case, these are:
im.shape[0]
545
im.shape[1]
1011
So the x-axis of the plot goes from 0 to 1011 and the y-axis from 0 to 545.
The map actually covers a range from -100 to +100 in the x-axis and -50 to 50 in the y-axis and my x,y coordinate values are on the same system.
How can I get the x-axis of the plot going from -100 to +100 and not 0 to 1011? a开发者_如何学运维nd then overplot my x,y scatter plot.
The following code, from the matplotlib site, shows a plot that goes from -3 to 3, check it out:
#!/usr/bin/env python
import numpy as np
import matplotlib.cm as cm
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
delta = 0.025
x = y = np.arange(-3.0, 3.0, delta)
X, Y = np.meshgrid(x, y)
Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
Z = Z2-Z1 # difference of Gaussians
im = plt.imshow(Z, interpolation='bilinear', cmap=cm.gray,
origin='lower', extent=[-3,3,-3,3])
plt.show()
The important part is the 'extent' argument of 'imshow'.
精彩评论