## matplotlib-users

 [Matplotlib-users] A matlab-like 'axis equal' command From: Mark Bakker - 2005-07-01 23:07:14 Attachments: Message as HTML ```Hello - I wrote a small function that scales the axes so that the true scale (e.g.= =20 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= =20 meters, for example. It is equivalent to the 'axis equal' command in matlab= .=20 Except that once given that command in matlab it is persistent. Here you=20 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=20 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= =20 release? Or are there better ways to do this? Mark def axis_equal(self): figwidth,figheight =3D self.canvas.figure.get_size_inches() figwidth =3D 0.8*figwidth; figheight =3D 0.8*figheight ax =3D self.canvas.figure.gca() x1,x2 =3D ax.get_xlim() y1,y2 =3D ax.get_ylim() plotheight =3D y2-y1 plotwidth =3D x2-x1 if plotheight/plotwidth > figheight/figwidth: # Plot is higher than figure wfrac =3D figheight/figwidth * plotwidth/plotheight hfrac =3D 1.0 else: hfrac =3D figwidth/figheight * plotheight/plotwidth wfrac =3D 1.0 self.canvas.figure.subplots_adjust( left =3D 0.1, right =3D 0.1+wfrac*0.8,= =20 bottom =3D 0.1, top =3D 0.1+hfrac*0.8 ) draw_if_interactive() ```
 Re: [Matplotlib-users] A matlab-like 'axis equal' command From: John Hunter - 2005-07-06 13:41:00 ```>>>>> "Mark" == Mark Bakker writes: Mark> Hello - I wrote a small function that scales the axes so Mark> that the true scale (e.g. the coordinates per inch) are the Mark> same along each axis. This is useful when you contour Mark> spatial data where the x and y axes are in meters, for Mark> example. It is equivalent to the 'axis equal' command in Mark> matlab. Except that once given that command in matlab it is Mark> persistent. Here you have to push the button every time you Mark> changed the figure window or zoom. Hey Mark, Did you know there is already an "equal" option to the axis command. If it doesn't work right, could you fix it and send me a patch? Mark> I added the function to the toolbar2 class and added a Mark> button to the toolbar. For the Tk backend this works great. Mark> And I don't think it is back-end dependent, but then again, Mark> what do I know. Mark> Any chance that such a button on the toolbar can be added to Mark> the official release? Or are there better ways to do this? This kind of button is useful to many but not others, and is a perfect candidate for a modular toolbar. We've talked in the past about supporting customized toolbars, with a contrib module for user defined tool functions. But this has stalled in part because modifying the toolbar across many GUIs is a pain. One solution would be to use matplotlib buttons in a GUI neutral toolbar -- then customizing it would be trivial and would work for free across backends. Perhaps you should post a patch or code so others could test your button and see if they like it enough to put it on the standard toolbar until we get support for custom, extensible toolbars. JDH ```
 Re: [Matplotlib-users] A matlab-like 'axis equal' command From: Mark Bakker - 2005-07-06 17:01:41 Attachments: Message as HTML ```John - The current option for 'axis('equal') only sets the coordinate range the=20 same on each axis, correct? What I want is to have the lengths of the axes scaled according to the=20 min/max values along the x and y axes. That is important when you contour spatial data, for example.=20 That's the button I made. I understand the hassle of adding a button that works on all back-ends. I'll try to post my button for the TK back-end and we'll take it from there= . Mark On 7/6/05, John Hunter wrote: >=20 > >>>>> "Mark" =3D=3D Mark Bakker writes: >=20 > Mark> Hello - I wrote a small function that scales the axes so > Mark> that the true scale (e.g. the coordinates per inch) are the > Mark> same along each axis. This is useful when you contour > Mark> spatial data where the x and y axes are in meters, for > Mark> example. It is equivalent to the 'axis equal' command in > Mark> matlab. Except that once given that command in matlab it is > Mark> persistent. Here you have to push the button every time you > Mark> changed the figure window or zoom. >=20 > Hey Mark, >=20 > Did you know there is already an "equal" option to the axis command. > If it doesn't work right, could you fix it and send me a patch? >=20 > Mark> I added the function to the toolbar2 class and added a > Mark> button to the toolbar. For the Tk backend this works great. > Mark> And I don't think it is back-end dependent, but then again, > Mark> what do I know. >=20 > Mark> Any chance that such a button on the toolbar can be added to > Mark> the official release? Or are there better ways to do this? >=20 > This kind of button is useful to many but not others, and is a perfect > candidate for a modular toolbar. We've talked in the past about > supporting customized toolbars, with a contrib module for user defined > tool functions. But this has stalled in part because modifying the > toolbar across many GUIs is a pain. One solution would be to use > matplotlib buttons in a GUI neutral toolbar -- then customizing it > would be trivial and would work for free across backends. >=20 > Perhaps you should post a patch or code so others could test your > button and see if they like it enough to put it on the standard > toolbar until we get support for custom, extensible toolbars. >=20 > JDH > ```
 Re: [Matplotlib-users] A matlab-like 'axis equal' command From: John Hunter - 2005-07-06 17:18:12 ```>>>>> "Mark" == Mark Bakker writes: Mark> John - The current option for 'axis('equal') only sets the Mark> coordinate range the same on each axis, correct? What I Mark> want is to have the lengths of the axes scaled according to Mark> the min/max values along the x and y axes. That is Mark> important when you contour spatial data, for example. Mark> That's the button I made. axis('equal') should work like matlab's option. Your post suggests that your version does and I infer therefore that the current axis('equal') does not. I'm wondering if we should substitute your version in there. Even if not, we can do both, with a suitably named flag. Would you be willing to incorporate your suggestion into the axis function and submit it as a patch to the sf site? Mark> I understand the hassle of adding a button that works on all Mark> back-ends. I'll try to post my button for the TK back-end Mark> and we'll take it from there. Sounds good. JDH ```