@@ -1998,24 +1998,22 @@ def plot_series(data, kind='line', ax=None, # Series unique
1998
1998
----------
1999
1999
column : str or list of str, optional
2000
2000
Column name or list of names, or vector.
2001
- Can be any valid input to groupby.
2002
- by : str or array-like
2003
- Column in the DataFrame to groupby.
2004
- ax : object of class matplotlib.axes.Axes, default `None`
2001
+ Can be any valid input to :meth:`pandas.DataFrame.groupby`.
2002
+ by : str or array-like, optional
2003
+ Column in the DataFrame to :meth:`pandas.DataFrame.groupby`.
2004
+ One box-plot will be done per value of columns in `by`.
2005
+ ax : object of class matplotlib.axes.Axes, optional
2005
2006
The matplotlib axes to be used by boxplot.
2006
2007
fontsize : float or str
2007
- Tick label font size in points or as a string (e.g., ‘large’)
2008
- (see `matplotlib.axes.Axes.tick_params
2009
- <https://matplotlib.org/api/_as_gen/
2010
- matplotlib.axes.Axes.tick_params.html>`_).
2008
+ Tick label font size in points or as a string (e.g., ‘large’).
2011
2009
rot : int or float, default 0
2012
2010
The rotation angle of labels (in degrees)
2013
2011
with respect to the screen coordinate sytem.
2014
- grid : boolean, default ` True`
2012
+ grid : boolean, default True
2015
2013
Setting this to True will show the grid.
2016
2014
figsize : A tuple (width, height) in inches
2017
2015
The size of the figure to create in matplotlib.
2018
- layout : tuple (rows, columns) ( optional)
2016
+ layout : tuple (rows, columns), optional
2019
2017
For example, (3, 5) will display the subplots
2020
2018
using 3 columns and 5 rows, starting from the top-left.
2021
2019
return_type : {None, 'axes', 'dict', 'both'}, default 'axes'
@@ -2026,22 +2024,13 @@ def plot_series(data, kind='line', ax=None, # Series unique
2026
2024
Lines of the boxplot.
2027
2025
* 'both' returns a namedtuple with the axes and dict.
2028
2026
* when grouping with ``by``, a Series mapping columns to
2029
- ``return_type`` is returned (i.e.
2030
- ``df.boxplot(column=['Col1','Col2'], by='var',return_type='axes')``
2031
- may return ``Series([AxesSubplot(..),AxesSubplot(..)],
2032
- index=['Col1','Col2'])``).
2027
+ ``return_type`` is returned.
2033
2028
2034
2029
If ``return_type`` is `None`, a NumPy array
2035
- of axes with the same shape as ``layout`` is returned
2036
- (i.e. ``df.boxplot(column=['Col1','Col2'],
2037
- by='var',return_type=None)`` may return a
2038
- ``array([<matplotlib.axes._subplots.AxesSubplot object at ..>,
2039
- <matplotlib.axes._subplots.AxesSubplot object at ..>],
2040
- dtype=object)``).
2041
- **kwds : Keyword Arguments (optional)
2030
+ of axes with the same shape as ``layout`` is returned.
2031
+ **kwds : Keyword Arguments, optional
2042
2032
All other plotting keyword arguments to be passed to
2043
- `matplotlib.pyplot.boxplot <https://matplotlib.org/api/_as_gen/
2044
- matplotlib.pyplot.boxplot.html#matplotlib.pyplot.boxplot>`_.
2033
+ :func:`matplotlib.pyplot.boxplot`.
2045
2034
2046
2035
Returns
2047
2036
-------
@@ -2059,8 +2048,8 @@ def plot_series(data, kind='line', ax=None, # Series unique
2059
2048
2060
2049
See Also
2061
2050
--------
2062
- matplotlib.pyplot.boxplot: Make a box and whisker plot.
2063
- matplotlib.pyplot.hist: Make a hsitogram .
2051
+ matplotlib.pyplot.boxplot : Make a box and whisker plot.
2052
+ matplotlib.pyplot.hist : Make a histogram .
2064
2053
2065
2054
Notes
2066
2055
-----
@@ -2078,27 +2067,27 @@ def plot_series(data, kind='line', ax=None, # Series unique
2078
2067
:context: close-figs
2079
2068
2080
2069
>>> np.random.seed(1234)
2081
- >>> df = pd.DataFrame(np.random.rand (10,4),
2070
+ >>> df = pd.DataFrame(np.random.randn (10,4),
2082
2071
... columns=['Col1', 'Col2', 'Col3', 'Col4'])
2083
2072
>>> boxplot = df.boxplot(column=['Col1', 'Col2', 'Col3'])
2084
2073
2085
- Boxplots of variables distributions grouped by a third variable values
2086
- can be created using the option ``by``. For instance:
2074
+ Boxplots of variables distributions grouped by the values of a third
2075
+ variable can be created using the option ``by``. For instance:
2087
2076
2088
2077
.. plot::
2089
2078
:context: close-figs
2090
2079
2091
- >>> df = pd.DataFrame(np.random.rand (10,2), columns=['Col1', 'Col2'] )
2080
+ >>> df = pd.DataFrame(np.random.randn (10,2), columns=['Col1', 'Col2'] )
2092
2081
>>> df['X'] = pd.Series(['A','A','A','A','A','B','B','B','B','B'])
2093
2082
>>> boxplot = df.boxplot(by='X')
2094
2083
2095
- A list of strings (i.e. ``['X','Y']``) containing can be passed to boxplot
2084
+ A list of strings (i.e. ``['X','Y']``) can be passed to boxplot
2096
2085
in order to group the data by combination of the variables in the x-axis:
2097
2086
2098
2087
.. plot::
2099
2088
:context: close-figs
2100
2089
2101
- >>> df = pd.DataFrame(np.random.rand (10,3),
2090
+ >>> df = pd.DataFrame(np.random.randn (10,3),
2102
2091
... columns=['Col1', 'Col2', 'Col3'])
2103
2092
>>> df['X'] = pd.Series(['A','A','A','A','A','B','B','B','B','B'])
2104
2093
>>> df['Y'] = pd.Series(['A','B','A','B','A','B','A','B','A','B'])
@@ -2109,7 +2098,7 @@ def plot_series(data, kind='line', ax=None, # Series unique
2109
2098
.. plot::
2110
2099
:context: close-figs
2111
2100
2112
- >>> df = pd.DataFrame(np.random.rand (10,2), columns=['Col1', 'Col2'])
2101
+ >>> df = pd.DataFrame(np.random.randn (10,2), columns=['Col1', 'Col2'])
2113
2102
>>> df['X'] = pd.Series(['A','A','A','A','A','B','B','B','B','B'])
2114
2103
>>> boxplot = df.boxplot(by='X', layout=(2,1))
2115
2104
@@ -2121,6 +2110,73 @@ def plot_series(data, kind='line', ax=None, # Series unique
2121
2110
:context: close-figs
2122
2111
2123
2112
>>> boxplot = df.boxplot(grid=False, rot=45, fontsize=15)
2113
+
2114
+
2115
+ The parameter ``return_type`` can be used to select the type of element
2116
+ returned by `boxplot`. When ``return_type='axes'`` is selected,
2117
+ the matplotlib axes on which the boxplot is drawn are returned:
2118
+
2119
+ >>> df.boxplot(column=['Col1','Col2'], return_type='axes')
2120
+ <matplotlib.axes._subplots.AxesSubplot object at ...>
2121
+
2122
+ If selecting ``return_type='dict'`` a dictionary containing the
2123
+ lines is returned:
2124
+
2125
+ >>> df.boxplot(column=['Col1','Col2'], return_type='dict')
2126
+ {'boxes': [<matplotlib.lines.Line2D at ...>,
2127
+ <matplotlib.lines.Line2D at ...>],
2128
+ 'caps': [<matplotlib.lines.Line2D at ...>,
2129
+ <matplotlib.lines.Line2D at ...>,
2130
+ <matplotlib.lines.Line2D at ...>,
2131
+ <matplotlib.lines.Line2D at ...>],
2132
+ 'fliers': [<matplotlib.lines.Line2D at ...>,
2133
+ <matplotlib.lines.Line2D at ...>],
2134
+ 'means': [],
2135
+ 'medians': [<matplotlib.lines.Line2D at ...>,
2136
+ <matplotlib.lines.Line2D at ...>],
2137
+ 'whiskers': [<matplotlib.lines.Line2D at ...>,
2138
+ <matplotlib.lines.Line2D at ...>,
2139
+ <matplotlib.lines.Line2D at ...>,
2140
+ <matplotlib.lines.Line2D at ...>]}
2141
+
2142
+ If selecting ``return_type='both'``, a namedtuple with matplotlib axes and
2143
+ Line objets is returned:
2144
+
2145
+ >>> df.boxplot(column=['Col1','Col2'], return_type='both')
2146
+ Boxplot(ax=<matplotlib.axes._subplots.AxesSubplot object
2147
+ at 0x115821128>, lines={'whiskers':
2148
+ [<matplotlib.lines.Line2D object at ...>,
2149
+ <matplotlib.lines.Line2D object at ...>,
2150
+ <matplotlib.lines.Line2D object at ...>,
2151
+ <matplotlib.lines.Line2D object at ...>],
2152
+ 'caps': [<matplotlib.lines.Line2D object at ...>,
2153
+ <matplotlib.lines.Line2D object at ...>,
2154
+ <matplotlib.lines.Line2D object at ...>,
2155
+ <matplotlib.lines.Line2D object at ...>],
2156
+ 'boxes': [<matplotlib.lines.Line2D object at ...>,
2157
+ <matplotlib.lines.Line2D object at ...>],
2158
+ 'medians': [<matplotlib.lines.Line2D object at ...>,
2159
+ <matplotlib.lines.Line2D object at ...>],
2160
+ 'fliers': [<matplotlib.lines.Line2D object at ...>,
2161
+ <matplotlib.lines.Line2D object at ...>], 'means': []})
2162
+
2163
+ When grouping with ``by``, a Series mapping columns to ``return_type``
2164
+ is returned:
2165
+
2166
+
2167
+ >>> df.boxplot(column=['Col1','Col2'], by='X', return_type='axes')
2168
+ Col1 AxesSubplot(0.1,0.15;0.363636x0.75)
2169
+ Col2 AxesSubplot(0.536364,0.15;0.363636x0.75)
2170
+ dtype: object
2171
+
2172
+ If ``return_type`` is `None`, a NumPy array of axes with the same shape
2173
+ as ``layout`` is returned:
2174
+
2175
+ >>> df.boxplot(column=['Col1','Col2'], by='X', return_type=None)
2176
+ array([<matplotlib.axes._subplots.AxesSubplot object at ...>,
2177
+ <matplotlib.axes._subplots.AxesSubplot object at ...>],
2178
+ dtype=object)
2179
+
2124
2180
"""
2125
2181
2126
2182
@Appender (_shared_docs ['boxplot' ] % _shared_doc_kwargs )
0 commit comments