Change range withouth scaling in matplot
Asked Answered
A

1

0

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()


Edit: @ImportanceOfBeingErnest's answer worked as expected! Now I am having another problem, in the canvas I am showing the image, the x-axis and y-axis doesnt visualize correctly, here is an image example how could I fix it? thanks.
Aftercare answered 7/4, 2017 at 17:8 Comment(0)
K
1

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])


Answer to the edited question:
In the case of the image being too large, this is probably caused by you setting 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.
Karole answered 7/4, 2017 at 17:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.