@@ -384,7 +384,7 @@ def set_zmargin(self, m):
384384 self ._zmargin = m
385385 self .stale = True
386386
387- def margins (self , * args , ** kw ):
387+ def margins (self , * margins , x = None , y = None , z = None , tight = True ):
388388 """
389389 Convenience method to set or retrieve autoscaling margins.
390390
@@ -404,8 +404,12 @@ def margins(self, *args, **kw):
404404 margins(..., tight=False)
405405
406406 All forms above set the xmargin, ymargin and zmargin
407- parameters. All keyword parameters are optional. A single argument
408- specifies xmargin, ymargin and zmargin. The *tight* parameter
407+ parameters. All keyword parameters are optional. A single
408+ positional argument specifies xmargin, ymargin and zmargin.
409+ Passing both positional and keyword arguments for xmargin,
410+ ymargin, and/or zmargin is invalid.
411+
412+ The *tight* parameter
409413 is passed to :meth:`autoscale_view`, which is executed after
410414 a margin is changed; the default here is *True*, on the
411415 assumption that when margins are specified, no additional
@@ -420,41 +424,33 @@ def margins(self, *args, **kw):
420424 .. versionadded :: 1.1.0
421425 This function was added, but not tested. Please report any bugs.
422426 """
423- if not args and not kw :
427+ if margins and x is not None and y is not None and z is not None :
428+ raise TypeError ('Cannot pass both positional and keyword '
429+ 'arguments for x, y, and/or z.' )
430+ elif len (margins ) == 1 :
431+ x = y = z = margins [0 ]
432+ elif len (margins ) == 3 :
433+ x , y , z = margins
434+ elif margins :
435+ raise TypeError ('Must pass a single positional argument for all '
436+ 'margins, or one for each margin (x, y, z).' )
437+
438+ if x is None and y is None and z is None :
439+ if tight is not True :
440+ warnings .warn ('ignoring tight=%r in get mode' % (tight ,))
424441 return self ._xmargin , self ._ymargin , self ._zmargin
425442
426- tight = kw .pop ('tight' , True )
427- mx = kw .pop ('x' , None )
428- my = kw .pop ('y' , None )
429- mz = kw .pop ('z' , None )
430- if not args :
431- pass
432- elif len (args ) == 1 :
433- mx = my = mz = args [0 ]
434- elif len (args ) == 2 :
435- warnings .warn (
436- "Passing exactly two positional arguments to Axes3D.margins "
437- "is deprecated. If needed, pass them as keyword arguments "
438- "instead" , cbook .mplDeprecation )
439- mx , my = args
440- elif len (args ) == 3 :
441- mx , my , mz = args
442- else :
443- raise ValueError (
444- "Axes3D.margins takes at most three positional arguments" )
445- if mx is not None :
446- self .set_xmargin (mx )
447- if my is not None :
448- self .set_ymargin (my )
449- if mz is not None :
450- self .set_zmargin (mz )
451-
452- scalex = mx is not None
453- scaley = my is not None
454- scalez = mz is not None
443+ if x is not None :
444+ self .set_xmargin (x )
445+ if y is not None :
446+ self .set_ymargin (y )
447+ if z is not None :
448+ self .set_zmargin (z )
455449
456- self .autoscale_view (tight = tight , scalex = scalex , scaley = scaley ,
457- scalez = scalez )
450+ self .autoscale_view (
451+ tight = tight , scalex = (x is not None ), scaley = (y is not None ),
452+ scalez = (z is not None )
453+ )
458454
459455 def autoscale (self , enable = True , axis = 'both' , tight = None ):
460456 """
0 commit comments