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