-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
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
Changes from 2 commits
a2b2e24
209d8a0
b231f36
c6e6ca2
d3595e5
09065f8
1892d35
a5897d5
18fc6e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
Allows plotting of one column versus another. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In our case it worked with |
||
Keyword arguments to pass on to :py:meth:`pandas.DataFrame.plot`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you rephrase this as |
||
|
||
Returns | ||
------- | ||
axes : matplotlib.AxesSubplot or np.array of them | ||
|
||
Examples | ||
-------- | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
||
|
There was a problem hiding this comment.
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)