Skip to content

Commit ad58045

Browse files
committed
cleanup pyplot.axes()
1 parent 0943a6c commit ad58045

File tree

1 file changed

+59
-45
lines changed

1 file changed

+59
-45
lines changed

lib/matplotlib/pyplot.py

+59-45
Original file line numberDiff line numberDiff line change
@@ -863,60 +863,74 @@ def over(func, *args, **kwargs):
863863
## Axes ##
864864

865865

866-
def axes(*args, **kwargs):
866+
def axes(arg=None, **kwargs):
867867
"""
868-
Add an axes to the figure.
869-
870-
The axes is added at position *rect* specified by:
871-
872-
- ``axes()`` by itself creates a default full ``subplot(111)`` window axis.
873-
874-
- ``axes(rect, facecolor='w')`` where *rect* = [left, bottom, width,
875-
height] in normalized (0, 1) units. *facecolor* is the background
876-
color for the axis, default white.
877-
878-
- ``axes(h)`` where *h* is an axes instance makes *h* the current
879-
axis and the parent of *h* the current figure.
880-
An :class:`~matplotlib.axes.Axes` instance is returned.
881-
882-
========= ============== ==============================================
883-
kwarg Accepts Description
884-
========= ============== ==============================================
885-
facecolor color the axes background color
886-
frameon [True|False] display the frame?
887-
sharex otherax current axes shares xaxis attribute
888-
with otherax
889-
sharey otherax current axes shares yaxis attribute
890-
with otherax
891-
polar [True|False] use a polar axes?
892-
aspect [str | num] ['equal', 'auto'] or a number. If a number
893-
the ratio of x-unit/y-unit in screen-space.
894-
Also see
895-
:meth:`~matplotlib.axes.Axes.set_aspect`.
896-
========= ============== ==============================================
897-
898-
Examples:
899-
900-
* :file:`examples/pylab_examples/axes_demo.py` places custom axes.
901-
* :file:`examples/pylab_examples/shared_axis_demo.py` uses
902-
*sharex* and *sharey*.
868+
Add an axes to the current figure and makes it the current axes.
869+
870+
Parameters
871+
----------
872+
arg : None or Axes or 4-tuple
873+
The exact behavior of this function depends on the type:
874+
875+
- *None*: A new full window axes is added using
876+
``subplot(111, **kwargs)``
877+
- 4-tuple of floats *rect* = ``[left, bottom, width, height]``.
878+
A new axes is added with dimensions *rect* in normalized
879+
(0, 1) units using `~.Figure.add_axes` on the current figure.
880+
- `~.Axes`: The is is equivalent to `.pyplot.sca`. It sets the current
881+
axes to *arg*. Note: This implicitly changes the current figure to
882+
the parent of *arg*.
883+
884+
Other Parameters
885+
----------------
886+
kwargs :
887+
For allowed keyword arguments see `.pyplot.subplot` and
888+
`.Figure.add_axes` respectively. Some common keyword arguments are
889+
listed below:
890+
891+
========= ============== ==============================================
892+
kwarg Accepts Description
893+
========= ============== ==============================================
894+
facecolor color the axes background color
895+
frameon [True|False] display the frame?
896+
sharex otherax current axes shares xaxis attribute
897+
with otherax
898+
sharey otherax current axes shares yaxis attribute
899+
with otherax
900+
polar [True|False] use a polar axes?
901+
aspect [str | num] ['equal', 'auto'] or a number. If a number
902+
the ratio of y-unit/x-unit in screen-space.
903+
Also see
904+
:meth:`~matplotlib.axes.Axes.set_aspect`.
905+
========= ============== ==============================================
906+
907+
Returns
908+
-------
909+
axes : Axes
910+
The created or activated axes.
911+
912+
Examples
913+
--------
914+
Creating a new full window axes::
915+
916+
>>> plt.axes()
917+
918+
Creating a new axes with specified dimensions and somw kwargs::
919+
920+
>>> plt.axes((left, bottom, width, height), facecolor='w')
903921
904922
"""
905923

906-
nargs = len(args)
907-
if len(args) == 0:
924+
if arg is None:
908925
return subplot(111, **kwargs)
909-
if nargs > 1:
910-
raise TypeError('Only one non keyword arg to axes allowed')
911-
arg = args[0]
912926

913927
if isinstance(arg, Axes):
914-
sca(arg)
915-
a = arg
928+
ax = arg
929+
sca(ax)
930+
return ax
916931
else:
917932
rect = arg
918-
a = gcf().add_axes(rect, **kwargs)
919-
return a
933+
return gcf().add_axes(rect, **kwargs)
920934

921935

922936
def delaxes(*args):

0 commit comments

Comments
 (0)