Hello -
I wrote a small function that scales the axes so that the true scale
(e.g. the coordinates per inch) are the same along each axis.
This is useful when you contour spatial data where the x and y axes are
in meters, for example. It is equivalent to the ‘axis equal’ command in
matlab. Except that once given that command in matlab it is persistent.
Here you have to push the button every time you changed the figure
window or zoom.
I added the function to the toolbar2 class and added a button to the toolbar.
For the Tk backend this works great.
And I don’t think it is back-end dependent, but then again, what do I know.
Any chance that such a button on the toolbar can be added to the official release?
Or are there better ways to do this?
Mark
def axis_equal(self):
figwidth,figheight = self.canvas.figure.get_size_inches()
figwidth = 0.8*figwidth; figheight = 0.8*figheight
ax = self.canvas.figure.gca()
x1,x2 = ax.get_xlim()
y1,y2 = ax.get_ylim()
plotheight = y2-y1
plotwidth = x2-x1
if plotheight/plotwidth > figheight/figwidth: # Plot is higher than figure
wfrac = figheight/figwidth * plotwidth/plotheight
hfrac = 1.0
else:
hfrac = figwidth/figheight * plotheight/plotwidth
wfrac = 1.0
self.canvas.figure.subplots_adjust( left = 0.1, right = 0.1+wfrac0.8,
bottom = 0.1, top = 0.1+hfrac0.8 )
draw_if_interactive()