Skip to content

DOC/PLT: Add stacked in doc and doc example for barh and bar plot #33337

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 24 commits into from
May 6, 2020
Merged
Changes from 13 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7e461a1
remove \n from docstring
charlesdong1991 Dec 3, 2018
1314059
fix conflicts
charlesdong1991 Jan 19, 2019
8bcb313
Merge remote-tracking branch 'upstream/master'
charlesdong1991 Jul 30, 2019
24c3ede
Merge remote-tracking branch 'upstream/master'
charlesdong1991 Jan 14, 2020
dea38f2
fix issue 17038
charlesdong1991 Jan 14, 2020
cd9e7ac
revert change
charlesdong1991 Jan 14, 2020
e5e912b
revert change
charlesdong1991 Jan 14, 2020
045a76f
Merge remote-tracking branch 'upstream/master'
charlesdong1991 Apr 6, 2020
f3513b0
Add stacked in doc for bar/h
charlesdong1991 Apr 6, 2020
aced183
fixup
charlesdong1991 Apr 6, 2020
ae796b6
fix pep8
charlesdong1991 Apr 6, 2020
11d7644
better example
charlesdong1991 Apr 6, 2020
d1c5a3f
fix linting
charlesdong1991 Apr 6, 2020
8d462f9
spaces
charlesdong1991 Apr 7, 2020
ef32ea2
Merge remote-tracking branch 'upstream/master' into add_stacked_doc
charlesdong1991 Apr 10, 2020
0ba8e2f
fix typo
charlesdong1991 Apr 11, 2020
ee3599a
Merge remote-tracking branch 'upstream/master' into add_stacked_doc
charlesdong1991 Apr 11, 2020
15b4319
fix typo
charlesdong1991 Apr 11, 2020
f01036b
Merge remote-tracking branch 'upstream/master' into add_stacked_doc
charlesdong1991 Apr 11, 2020
c5c6bbe
Merge remote-tracking branch 'upstream/master' into add_stacked_doc
charlesdong1991 Apr 15, 2020
cd076af
Merge remote-tracking branch 'upstream/master' into add_stacked_doc
charlesdong1991 Apr 16, 2020
dfd7b5d
Merge remote-tracking branch 'upstream/master' into add_stacked_doc
charlesdong1991 May 1, 2020
c18fc21
remove doc
charlesdong1991 May 1, 2020
629d639
Merge remote-tracking branch 'upstream/master' into add_stacked_doc
charlesdong1991 May 5, 2020
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
20 changes: 20 additions & 0 deletions pandas/plotting/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,9 @@ def line(self, x=None, y=None, **kwargs):

@Appender(
"""
stacked: bool, default is False
Copy link
Member

@ShaharNaveh ShaharNaveh Apr 6, 2020

Choose a reason for hiding this comment

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

Suggested change
stacked: bool, default is False
stacked : bool, default False

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks!

If stacked is set to True, stacked bar charts will be plotted.

See Also
--------
DataFrame.plot.barh : Horizontal bar plot.
Expand Down Expand Up @@ -985,6 +988,13 @@ def line(self, x=None, y=None, **kwargs):
... 'lifespan': lifespan}, index=index)
>>> ax = df.plot.bar(rot=0)

Plot stacked bar chars for the DataFrame
Copy link
Member

Choose a reason for hiding this comment

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

Should this be ‘bar charts’?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops! 😅 Nice catch!


.. plot::
:context: close-figs

>>> ax = df.plot.bar(stacked=True)

Instead of nesting, the figure can be split by column with
``subplots=True``. In this case, a :class:`numpy.ndarray` of
:class:`matplotlib.axes.Axes` are returned.
Expand Down Expand Up @@ -1037,6 +1047,9 @@ def bar(self, x=None, y=None, **kwargs):

@Appender(
"""
stacked: bool, default is False
Copy link
Member

@ShaharNaveh ShaharNaveh Apr 6, 2020

Choose a reason for hiding this comment

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

Suggested change
stacked: bool, default is False
stacked : bool, default False

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks!

If stacked is set to True, stacked horizontal bar charts will be plotted.

See Also
--------
DataFrame.plot.bar: Vertical bar plot.
Expand Down Expand Up @@ -1066,6 +1079,13 @@ def bar(self, x=None, y=None, **kwargs):
... 'lifespan': lifespan}, index=index)
>>> ax = df.plot.barh()

Plot stacked bar chars for the DataFrame
Copy link
Member

Choose a reason for hiding this comment

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

Same here?

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks!


.. plot::
:context: close-figs

>>> ax = df.plot.bar(stacked=True)

We can specify colors for each column

.. plot::
Expand Down