3939import matplotlib .transforms as mtransforms
4040import matplotlib .tri as mtri
4141from matplotlib .cbook import (
42- _backports , mplDeprecation , STEP_LOOKUP_MAP , iterable , safe_first_element )
42+ _backports , mplDeprecation , warn_deprecated ,
43+ STEP_LOOKUP_MAP , iterable , safe_first_element )
4344from matplotlib .container import BarContainer , ErrorbarContainer , StemContainer
4445from matplotlib .axes ._base import _AxesBase , _process_plot_format
4546
@@ -2515,27 +2516,109 @@ def stem(self, *args, **kwargs):
25152516 """
25162517 Create a stem plot.
25172518
2518- Call signatures::
2519+ A stem plot plots vertical lines at each *x* location from the baseline
2520+ to *y*, and places a marker there.
2521+
2522+ Call signature::
2523+
2524+ stem([x,] y, linefmt=None, markerfmt=None, basefmt=None)
2525+
2526+ The x-positions are optional. The formats may be provided either as
2527+ positional or as keyword-arguments.
2528+
2529+ Parameters
2530+ ----------
2531+ x : array-like, optional
2532+ The x-positions of the stems. Default: (0, 1, ..., len(y) - 1).
2533+
2534+ y : array-like
2535+ The y-values of the stem heads.
2536+
2537+ linefmt : str, optional
2538+ A string defining the properties of the vertical lines. Usually,
2539+ this will be a color or a color and a linestyle:
2540+
2541+ ========= =============
2542+ Character Line Style
2543+ ========= =============
2544+ ``'-'`` solid line
2545+ ``'--'`` dashed line
2546+ ``'-.'`` dash-dot line
2547+ ``':'`` dotted line
2548+ ========= =============
2549+
2550+ Default: 'C0-', i.e. solid line with the first color of the color
2551+ cycle.
25192552
2520- stem(y, linefmt='b-', markerfmt='bo', basefmt='r-')
2521- stem(x, y, linefmt='b-', markerfmt='bo', basefmt='r-')
2553+ Note: While it is technically possible to specify valid formats
2554+ other than color or color and linestyle (e.g. 'rx' or '-.'), this
2555+ is beyond the intention of the method and will most likely not
2556+ result in a reasonable reasonable plot.
25222557
2523- A stem plot plots vertical lines (using *linefmt*) at each *x*
2524- location from the baseline to *y*, and places a marker there
2525- using *markerfmt*. A horizontal line at 0 is plotted using
2526- *basefmt* .
2558+ markerfmt : str, optional
2559+ A string defining the properties of the markers at the stem heads.
2560+ Default: 'C0o', i.e. filled circles with the first color of the
2561+ color cycle .
25272562
2528- If no *x* values are provided, the default is (0, 1, ..., len(y) - 1)
2563+ basefmt : str, optional
2564+ A format string defining the properties of the baseline.
2565+
2566+ Default: 'C3-' ('C2-' in classic mode).
2567+
2568+ bottom : float, optional, default: 0
2569+ The y-position of the baseline.
2570+
2571+ label : str, optional, default: None
2572+ The label to use for the stems in legends.
2573+
2574+
2575+ Other Parameters
2576+ ----------------
2577+ **kwargs
2578+ No other parameters are supported. They are currently ignored
2579+ silently for backward compatibility. This behavior is deprecated.
2580+ Future versions will not accept any other parameters and will
2581+ raise a TypeError instead.
2582+
2583+
2584+ Returns
2585+ -------
2586+ :class:`~matplotlib.container.StemContainer`
2587+ The stemcontainer may be treated like a tuple
2588+ (*markerline*, *stemlines*, *baseline*)
25292589
2530- Return value is a tuple (*markerline*, *stemlines*,
2531- *baseline*). See :class:`~matplotlib.container.StemContainer`
2590+
2591+ Notes
2592+ -----
25322593
25332594 .. seealso::
2534- This
2535- `document <http://www.mathworks.com/help/techdoc/ref/stem.html>`_
2536- for details .
2595+ The MATLAB function
2596+ `stem <http://www.mathworks.com/help/techdoc/ref/stem.html>`_
2597+ which inspired this method .
25372598
25382599 """
2600+
2601+ # kwargs handling
2602+ # We would like to have a signature with explicit kewords:
2603+ # stem(*args, linefmt=None, markerfmt=None, basefmt=None,
2604+ # bottom=0, label=None)
2605+ # Unfortunately, this is not supported in Python 2.x. There, *args
2606+ # can only exist after keyword arguments.
2607+ linefmt = kwargs .pop ('linefmt' , None )
2608+ markerfmt = kwargs .pop ('markerfmt' , None )
2609+ basefmt = kwargs .pop ('basefmt' , None )
2610+ bottom = kwargs .pop ('bottom' , None )
2611+ if bottom is None :
2612+ bottom = 0
2613+ label = kwargs .pop ('label' , None )
2614+ if kwargs :
2615+ warn_deprecated (since = '2.2' ,
2616+ message = "stem() got an unexpected keyword "
2617+ "argument '%s'. This will raise a "
2618+ "TypeError in future versions." % (
2619+ next (k for k in kwargs ), )
2620+ )
2621+
25392622 remember_hold = self ._hold
25402623 if not self ._hold :
25412624 self .cla ()
@@ -2555,11 +2638,10 @@ def stem(self, *args, **kwargs):
25552638 second = np .arange (len (y ))
25562639 x = second
25572640
2558- # Popping some defaults
2559- try :
2560- linefmt = kwargs ['linefmt' ]
2561- except KeyError :
2641+ # defaults for formats
2642+ if linefmt is None :
25622643 try :
2644+ # fallback to positional argument
25632645 linefmt = args [0 ]
25642646 except IndexError :
25652647 linecolor = 'C0'
@@ -2570,10 +2652,10 @@ def stem(self, *args, **kwargs):
25702652 _process_plot_format (linefmt )
25712653 else :
25722654 linestyle , linemarker , linecolor = _process_plot_format (linefmt )
2573- try :
2574- markerfmt = kwargs ['markerfmt' ]
2575- except KeyError :
2655+
2656+ if markerfmt is None :
25762657 try :
2658+ # fallback to positional argument
25772659 markerfmt = args [1 ]
25782660 except IndexError :
25792661 markercolor = 'C0'
@@ -2585,10 +2667,10 @@ def stem(self, *args, **kwargs):
25852667 else :
25862668 markerstyle , markermarker , markercolor = \
25872669 _process_plot_format (markerfmt )
2588- try :
2589- basefmt = kwargs ['basefmt' ]
2590- except KeyError :
2670+
2671+ if basefmt is None :
25912672 try :
2673+ # fallback to positional argument
25922674 basefmt = args [2 ]
25932675 except IndexError :
25942676 if rcParams ['_internal.classic_mode' ]:
@@ -2603,15 +2685,9 @@ def stem(self, *args, **kwargs):
26032685 else :
26042686 basestyle , basemarker , basecolor = _process_plot_format (basefmt )
26052687
2606- bottom = kwargs .pop ('bottom' , None )
2607- label = kwargs .pop ('label' , None )
2608-
26092688 markerline , = self .plot (x , y , color = markercolor , linestyle = markerstyle ,
26102689 marker = markermarker , label = "_nolegend_" )
26112690
2612- if bottom is None :
2613- bottom = 0
2614-
26152691 stemlines = []
26162692 for thisx , thisy in zip (x , y ):
26172693 l , = self .plot ([thisx , thisx ], [bottom , thisy ],
0 commit comments