From bb46fea031c1ed7a8cffffecf81a84996c859c01 Mon Sep 17 00:00:00 2001 From: David Arcos Date: Sat, 10 Mar 2018 15:59:51 +0100 Subject: [PATCH 1/3] DOC: Improve docstring for pandas.DataFrame.plot.area --- pandas/plotting/_core.py | 76 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 71 insertions(+), 5 deletions(-) diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index e81b162645b94..a59d29c5f8e87 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -3337,19 +3337,85 @@ def kde(self, bw_method=None, ind=None, **kwds): def area(self, x=None, y=None, **kwds): """ - Area plot + Draw a stacked area plot. + + An area plot displays quantitative data visually. + This function wraps the matplotlib area function. Parameters ---------- - x, y : label or position, optional - Coordinates for each point. - `**kwds` : optional + x : label or position, optional + Index, coordinates for X axis. + y : label or position, optional + Index, coordinates for Y axis. + stacked : boolean, default True + Area plots are stacked by default. Set to False to create a + unstacked plot. + **kwds : optional Additional keyword arguments are documented in :meth:`pandas.DataFrame.plot`. Returns ------- - axes : :class:`matplotlib.axes.Axes` or numpy.ndarray of them + matplotlib.axes.Axes or numpy.ndarray + Area plot, or array of area plots if subplots is True + + See Also + -------- + pandas.DataFrame.plot : Draw plots. + + Examples + -------- + Draw an area plot based on basic business metrics: + + .. plot:: + :context: close-figs + + >>> df = pd.DataFrame({ + ... 'sales': [3, 2, 3, 9, 10, 6], + ... 'signups': [5, 5, 6, 12, 14, 13], + ... 'visits': [20, 42, 28, 62, 81, 50], + ... }) + >>> ax = df.plot.area() + + Area plots are stacked by default. To produce an unstacked plot, + pass ``stacked=False``: + + .. plot:: + :context: close-figs + + >>> df = pd.DataFrame({ + ... 'sales': [3, 2, 3, 9, 10, 6], + ... 'signups': [5, 5, 6, 12, 14, 13], + ... 'visits': [20, 42, 28, 62, 81, 50], + ... }) + >>> ax = df.plot.area(stacked=False) + + Draw an area plot for each metric: + + .. plot:: + :context: close-figs + + >>> df = pd.DataFrame({ + ... 'sales': [3, 2, 3, 9, 10, 6], + ... 'signups': [5, 5, 6, 12, 14, 13], + ... 'visits': [20, 42, 28, 62, 81, 50], + ... }) + >>> ax = df.plot.area(y='sales') + >>> ax = df.plot.area(y='signups') + >>> ax = df.plot.area(y='visits') + + Draw with a different `x`: + + .. plot:: + :context: close-figs + + >>> df = pd.DataFrame({ + ... 'sales': [3, 2, 3], + ... 'visits': [20, 42, 28], + ... 'day': ['Monday', 'Tuesday', 'Wednesday'], + ... }) + >>> ax = df.plot.area(x='day') """ return self(kind='area', x=x, y=y, **kwds) From a0df49741b61ce3cfc49f5c44ce9e272efe058fc Mon Sep 17 00:00:00 2001 From: David Arcos Date: Wed, 1 Aug 2018 14:43:47 +0200 Subject: [PATCH 2/3] Improved with suggestions --- pandas/plotting/_core.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index a59d29c5f8e87..a93e4d1d39bf7 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -3345,9 +3345,9 @@ def area(self, x=None, y=None, **kwds): Parameters ---------- x : label or position, optional - Index, coordinates for X axis. + Coordinates for the X axis. By default uses the index. y : label or position, optional - Index, coordinates for Y axis. + Column to plot. By default uses all columns. stacked : boolean, default True Area plots are stacked by default. Set to False to create a unstacked plot. @@ -3375,7 +3375,8 @@ def area(self, x=None, y=None, **kwds): ... 'sales': [3, 2, 3, 9, 10, 6], ... 'signups': [5, 5, 6, 12, 14, 13], ... 'visits': [20, 42, 28, 62, 81, 50], - ... }) + ... }, index=pd.date_range(start='2018/01/01', end='2018/07/01', + ... freq='M')) >>> ax = df.plot.area() Area plots are stacked by default. To produce an unstacked plot, @@ -3388,7 +3389,8 @@ def area(self, x=None, y=None, **kwds): ... 'sales': [3, 2, 3, 9, 10, 6], ... 'signups': [5, 5, 6, 12, 14, 13], ... 'visits': [20, 42, 28, 62, 81, 50], - ... }) + ... }, index=pd.date_range(start='2018/01/01', end='2018/07/01', + ... freq='M')) >>> ax = df.plot.area(stacked=False) Draw an area plot for each metric: @@ -3400,10 +3402,9 @@ def area(self, x=None, y=None, **kwds): ... 'sales': [3, 2, 3, 9, 10, 6], ... 'signups': [5, 5, 6, 12, 14, 13], ... 'visits': [20, 42, 28, 62, 81, 50], - ... }) + ... }, index=pd.date_range(start='2018/01/01', end='2018/07/01', + ... freq='M')) >>> ax = df.plot.area(y='sales') - >>> ax = df.plot.area(y='signups') - >>> ax = df.plot.area(y='visits') Draw with a different `x`: @@ -3414,7 +3415,8 @@ def area(self, x=None, y=None, **kwds): ... 'sales': [3, 2, 3], ... 'visits': [20, 42, 28], ... 'day': ['Monday', 'Tuesday', 'Wednesday'], - ... }) + ... }, index=pd.date_range(start='2018/01/01', end='2018/07/01', + ... freq='M')) >>> ax = df.plot.area(x='day') """ return self(kind='area', x=x, y=y, **kwds) From 3f02fe7f3da00d8258e70d1c249e126f4e4282aa Mon Sep 17 00:00:00 2001 From: David Arcos Date: Wed, 8 Aug 2018 18:05:57 +0200 Subject: [PATCH 3/3] More improvements --- pandas/plotting/_core.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index a93e4d1d39bf7..85b2738e572b6 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -3348,7 +3348,7 @@ def area(self, x=None, y=None, **kwds): Coordinates for the X axis. By default uses the index. y : label or position, optional Column to plot. By default uses all columns. - stacked : boolean, default True + stacked : bool, default True Area plots are stacked by default. Set to False to create a unstacked plot. **kwds : optional @@ -3362,7 +3362,7 @@ def area(self, x=None, y=None, **kwds): See Also -------- - pandas.DataFrame.plot : Draw plots. + DataFrame.plot : Make plots of DataFrame using matplotlib / pylab. Examples --------