Skip to content

DOC: update the pandas.DataFrame.plot.bar docsctring #20158

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 9 commits into from
Mar 13, 2018
Merged
Changes from 2 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
72 changes: 68 additions & 4 deletions pandas/plotting/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2721,18 +2721,82 @@ def line(self, x=None, y=None, **kwds):

def bar(self, x=None, y=None, **kwds):
"""
Vertical bar plot
Vertical bar plot.

A bar plot is a plot that presents categorical data with
rectangular bars with lengths proportional to the values that they
represent. A bar plot shows comparisons among discrete categories. One
axis of the plot shows the specific categories being compared, and the
other axis represents a measured value.

Parameters
----------
x, y : label or position, optional
Coordinates for each point.
`**kwds` : optional
x : label or position, default None
Copy link
Member

Choose a reason for hiding this comment

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

the 'optional' is actually better in this case than ', default None' (but it is a gray area in the docstring guide)

Allows plotting of one column versus another.
Copy link
Member

Choose a reason for hiding this comment

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

Can you specify what happens if it is not specified?

y : label or position, default None
Allows plotting of one column versus another.
**kwds : optional

Choose a reason for hiding this comment

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

Keyword arguments to pass on to :py:meth:`pandas.DataFrame.plot`.
Copy link
Member

Choose a reason for hiding this comment

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

Can you rephrase this as Additional keyword arguments are documented in meth:`pandas.DataFrame.plot` ?


Returns
-------
axes : matplotlib.AxesSubplot or np.array of them

Examples
--------

Copy link
Contributor

Choose a reason for hiding this comment

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

The empty line here is not necessary.

Basic plot

.. plot::
:context: close-figs

>>> df = pd.DataFrame({'lab':['A','B','C'], 'val':[10,30,20]})
>>> ax = df.plot.bar(x='lab',y='val')

Plot a whole dataframe to a bar plot

.. plot::
:context: close-figs

>>> speed = [0.1, 17.5, 40, 48, 52, 69, 88]
>>> lifespan = [2, 8, 70, 1.5, 25, 12, 28]
>>> index = ['snail', 'pig', 'elephant',
... 'rabbit', 'giraffe', 'coyote', 'horse']
>>> df = pd.DataFrame({'speed': speed,
... 'lifespan': lifespan}, index=index)
>>> ax = df.plot.bar()

Plot a column of the dataframe to a bar plot

.. plot::
:context: close-figs

>>> speed = [0.1, 17.5, 40, 48, 52, 69, 88]
>>> lifespan = [2, 8, 70, 1.5, 25, 12, 28]
>>> index = ['snail', 'pig', 'elephant',
... 'rabbit', 'giraffe', 'coyote', 'horse']
>>> df = pd.DataFrame({'speed': speed,
Copy link
Member

Choose a reason for hiding this comment

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

You don't need to redefine the dataframe here, it still knows it from the previous example

(and same below)

... 'lifespan': lifespan}, index=index)
>>> ax = df.plot.bar(y='speed')

Plot only selected categories for the dataframe

.. plot::
:context: close-figs

>>> speed = [0.1, 17.5, 40, 48, 52, 69, 88]
>>> lifespan = [2, 8, 70, 1.5, 25, 12, 28]
>>> index = ['snail', 'pig', 'elephant',
... 'rabbit', 'giraffe', 'coyote', 'horse']
>>> df = pd.DataFrame({'speed': speed,
... 'lifespan': lifespan}, index=index)
>>> ax = df.plot.bar(x='lifespan')

See Also
--------
pandas.DataFrame.plot.barh : Horizontal bar plot.
pandas.DataFrame.plot : Make plots of DataFrame using matplotlib.
matplotlib.pyplot.bar : Make a bar plot.
"""
return self(kind='bar', x=x, y=y, **kwds)

Expand Down