Skip to content

DOC: update the pandas.DataFrame.plot.area docstring #20170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 10, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 73 additions & 5 deletions pandas/plotting/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3337,19 +3337,87 @@ 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should follow the guide: https://python-sprints.github.io/pandas/guide/pandas_docstring.html#section-3-parameters

So it should indicate the type of the parameter in the first line (plus optional), and later the meaning of the parameter.

Coordinates for the X axis. By default uses the index.
y : label or position, optional
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @dukebody says, for both x and y, in the first line we should have the type, more than a short description. It's a bit tricky, as label can be anything, but I think we're using something like object or int, optional. Then, we can sure clarify that it's the label or the position in the description.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept it consistent with DataFrame.plot, which is the more complete docstring example I could find.

Column to plot. By default uses all columns.
stacked : bool, 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
--------
DataFrame.plot : Make plots of DataFrame using matplotlib / pylab.

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],
... }, 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,
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],
... }, index=pd.date_range(start='2018/01/01', end='2018/07/01',
... freq='M'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the .. plot:: directive resetting the namespace? Otherwise, It'd be good to reuse the DataFrame instead of repeating it in every example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had some issues with the namespace, so I kept it in different places.

Don't have the full environment right now, can't check if it also works the other way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recreating the dataframe each time should not be needed

>>> 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],
... }, index=pd.date_range(start='2018/01/01', end='2018/07/01',
... freq='M'))
>>> ax = df.plot.area(y='sales')

Draw with a different `x`:

.. plot::
:context: close-figs

>>> df = pd.DataFrame({
... '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'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example is not running (the index is not correct). And also the labels to not show on the actual plot once this is fixed.

>>> ax = df.plot.area(x='day')
"""
return self(kind='area', x=x, y=y, **kwds)

Expand Down