Reputation: 1129
I have a question, I am making a program that displays a zoomed area of Peru but the axis shown are in the range of the image (e.g. 7000x7500) but i want to be in UTM range (e.g. x-axis between 500000-600000 and y-axis 9500000-9700000)
I have tried using plt.set_xlim
and plt.sety_lim
but no success, I think I have to use plt.autoscale(False)
but it also didn't work or I used it wrong.
I create the figure and axes out of the main program
f = plt.figure(figsize=(5,5))
axe = f.add_axes([0, 0, 1, 1])
this is the function I call everytime I want to plot
def plotear(self, mapa):
axe.clear()
axe.imshow(mapa, cmap='gray', interpolation='nearest')
axe.set_xlim(0,10000) #This is just for testing
axe.set_ylim(0,10000) #This is just for testing
plt.autoscale(False)
self.canvas.draw()
Upvotes: 0
Views: 807
Reputation: 339340
From the imshow
documentation you'd find that there is an argument extent
which can be used to scale the image.
extent
: scalars (left, right, bottom, top), optional, default: None
The location, in data-coordinates, of the lower-left and upper-right corners. If None, the image is positioned such that the pixel centers fall on zero-based (row, column) indices.
In this case you'd use it like
ax.imshow(mapa, extent=[5e5, 6e5, 9.5e6, 9.7e6])
axe = f.add_axes([0, 0, 1, 1])
. You should rather use ax = fig.add_subplot(111)
and if the margins are not as you want then, setting plt.subplots_adjust( ... )
with the respective spacings.
Upvotes: 1