Skip to content

Commit

Permalink
Rebase, add docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Gorelli committed Jan 17, 2020
1 parent 213925f commit 87b297c
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
73 changes: 73 additions & 0 deletions pandas/plotting/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,21 @@ def line(self, x=None, y=None, **kwargs):
The values to be plotted.
Either the location or the label of the columns to be used.
By default, it will use the remaining DataFrame numeric columns.
color : str, int, array_like, or dict, optional
The color of each line for each row. Possible values are:
- A single color string referred to by name, RGB or RGBA code,
for instance 'red' or '#a98d19'.
- A sequence of color strings referred to by name, RGB or RGBA
code, which will be used for each line for each row recursively. For
instance ['green','yellow'] all lines for each row will be filled in green
or yellow, alternatively.
- A dict of the form {column name : color}, so that each row's lines will be
colored accordingly. For example, if your columns are called `a` and `b`,
then passing {'a': 'green', 'b': 'red'} will color the lines for column
`a` in green and lines for column `b` in red.
**kwargs
Keyword arguments to pass on to :meth:`DataFrame.plot`.
Expand Down Expand Up @@ -906,6 +921,16 @@ def line(self, x=None, y=None, **kwargs):
>>> type(axes)
<class 'numpy.ndarray'>
.. plot::
:context: close-figs
Let's repeat the same example, but specifying colors for
each column (in this case, for each animal).
>>> axes = df.plot.line(
... subplots=True, color={"pig": "pink", "horse": "#742802"}
... )
.. plot::
:context: close-figs
Expand Down Expand Up @@ -934,6 +959,21 @@ def bar(self, x=None, y=None, **kwargs):
y : label or position, optional
Allows plotting of one column versus another. If not specified,
all numerical columns are used.
color : str, int, array_like, or dict, optional
The color of each bar for each row. Possible values are:
- A single color string referred to by name, RGB or RGBA code,
for instance 'red' or '#a98d19'.
- A sequence of color strings referred to by name, RGB or RGBA
code, which will be used for each bar for each row recursively. For
instance ['green','yellow'] all bars for each row will be filled in green
or yellow, alternatively.
- A dict of the form {column name : color}, so that each row's bars will be
colored accordingly. For example, if your columns are called `a` and `b`,
then passing {'a': 'green', 'b': 'red'} will color bars for column `a` in
green and bars for column `b` in red.
**kwargs
Additional keyword arguments are documented in
:meth:`DataFrame.plot`.
Expand Down Expand Up @@ -985,6 +1025,17 @@ def bar(self, x=None, y=None, **kwargs):
>>> axes = df.plot.bar(rot=0, subplots=True)
>>> axes[1].legend(loc=2) # doctest: +SKIP
If we don't like the default colours, we can specify how we'd
like each column to be colored.
.. plot::
:context: close-figs
>>> axes = df.plot.bar(
... rot=0, subplots=True, color={"speed": "red", "lifespan": "green"}
... )
>>> axes[1].legend(loc=2) # doctest: +SKIP
Plot a single column.
.. plot::
Expand Down Expand Up @@ -1017,6 +1068,21 @@ def barh(self, x=None, y=None, **kwargs):
Column to be used for categories.
y : label or position, default All numeric columns in dataframe
Columns to be plotted from the DataFrame.
color : str, int, array_like, or dict, optional
The color of each bar for each row. Possible values are:
- A single color string referred to by name, RGB or RGBA code,
for instance 'red' or '#a98d19'.
- A sequence of color strings referred to by name, RGB or RGBA
code, which will be used for each bar for each row recursively. For
instance ['green','yellow'] all bars for each row will be filled in green
or yellow, alternatively.
- A dict of the form {column name : color}, so that each row's bars will be
colored accordingly. For example, if your columns are called `a` and `b`,
then passing {'a': 'green', 'b': 'red'} will color bars for column `a` in
green and bars for column `b` in red.
**kwargs
Keyword arguments to pass on to :meth:`DataFrame.plot`.
Expand Down Expand Up @@ -1053,6 +1119,13 @@ def barh(self, x=None, y=None, **kwargs):
... 'lifespan': lifespan}, index=index)
>>> ax = df.plot.barh()
We can specify colors for each column
.. plot::
:context: close-figs
>>> ax = df.plot.barh(color={"speed": "red", "lifespan": "green"})
Plot a column of the DataFrame to a horizontal bar plot
.. plot::
Expand Down
1 change: 1 addition & 0 deletions pandas/plotting/_matplotlib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,7 @@ def _make_plot(self):

pos_prior = neg_prior = np.zeros(len(self.data))
K = self.nseries

for i, (label, y) in enumerate(self._iter_data(fillna=0)):
ax = self._get_ax(i)
kwds = self.kwds.copy()
Expand Down

0 comments on commit 87b297c

Please sign in to comment.