Thanks for the explanation, John.
I printed out the CODING_GUIDE (sorry, didn't know it existed).
The new function with the extra copy command is shown below.
Can we add this to pylab?
Thanks, Mark
def aspect(*args, **kwargs):
"""
Set/Get the aspect ratio (ylength/xlength) of the current axis
Aspect ratio is defined as unit-length-along-y-axis /
unit-length-along-x-axis
If no arguments are passed, the current aspect ratio is returned
Aspect ratio may be met by changing size of axes while keeping data
limits fixed (called 'box'),
or by changing data limits while keeping the lengths of the axes fixed
(called 'datalim')
One point remains fixed, which is called the anchor, for example the
center (called 'C')
Autoscaling may be turned on (limits may change upon next plotting
command)
or off (limits will remain fixed)
Keyword arguments:
adjustable: 'box' (default), 'datalim'
anchor: 'C' (default), 'SW', 'S', 'SE', 'E', 'NE', 'N', 'NW', 'W'
fixlim: True (default), False
"""
ax = gca()
if len(args)==0:
aspect = ax.get_aspect()
elif len(args)==1:
aspect = args[0]
kwargs = kwargs.copy()
adjustable = popd(kwargs,'adjustable','box')
anchor = popd(kwargs,'anchor','C')
fixlim = popd(kwargs,'fixlim',True)
ax.set_aspect(aspect,adjustable,anchor)
if fixlim:
ax.set_autoscale_on(False)
else:
ax.set_autoscale_on(True)
ax.autoscale_view()
draw_if_interactive()
return aspect
On 2/26/07, John Hunter <[EMAIL PROTECTED]> wrote:
On 2/26/07, Mark Bakker <[EMAIL PROTECTED]> wrote:
> ax = gca()
> if len(args)==0:
> aspect = ax.get_aspect()
> elif len(args)==1:
> aspect = args[0]
> adjustable = popd(kwargs,'adjustable','box')
> anchor = popd(kwargs,'anchor','C')
> fixlim = popd(kwargs,'fixlim',True)
Whenever you are mutating a kwargs dictionary, eg with popd, you
should first copy it. The user may be creating, saving, and resuing a
kwarg dict
myaspectprops = dict(adjustable='box', anchor='NW')
# some code
aspect(**myaspectprops)
# some more code
aspect(**myaspectprops)
This will fail if you pop off of the kwargs in the aspect function w/o
first copying it. So always do
kwargs = kwargs.copy()
before calling popd and friends.
This is covered in the "CODING_GUIDE" document in the svn repository.
JDH
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users