Skip to content
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

ENH: support pie plot in series and dataframe plot #6976

Merged
merged 1 commit into from
May 5, 2014

Conversation

sinhrks
Copy link
Member

@sinhrks sinhrks commented Apr 27, 2014

Related to #413, added pie plot for Series.plot and DataFrame.plot kind.

If data includes NaN, it will be automatically filled by 0. If data contains negative value, ValueError will be raised.

import pandas as pd
import numpy as np
series = pd.Series(3 * np.random.rand(4), index=['a', 'b', 'c', 'd'], name='series')
series.plot(kind='pie')

series_pie_plot

Plotting with DataFrame

Pie plot with DataFrame requires either to specify target column by y argument or subplots=True. When y is specified, pie plot of selected column will be drawn. If subplots=True is specified, pie plots for each columns are drawn as subplots. Legend will be drawn in each pie plots by default, specify legend=False to hide it.

df = pd.DataFrame(3 * np.random.rand(4, 2), index=['a', 'b', 'c', 'd'], columns=['x', 'y'])
df.plot(kind='pie', subplots=True) 

df_pie_plot

Plotting with Options

You can use labels and colors keywords to specify labels and colors of each wedges (Cannot use label and color, because of matplotlib's specification). If you want to hide wedge labels, specify labels=None. If fontsize is specified, the value will be applied to wedge labels. Also, other keywords supported by matplotlib.pyplot.pie can be used.

series.plot(kind='pie', labels=['AA', 'BB', 'CC', 'DD'], colors=['r', 'g', 'b', 'c'],
               autopct='%.2f', fontsize=20)

series_pie_plot_options

@jreback
Copy link
Contributor

jreback commented Apr 27, 2014

@TomAugspurger I think it makes sense to make an additional sectin in plotting.rst to have basic/additional plots/advanced plots? (additional section is getting kind of long)?

@jreback jreback added this to the 0.14.0 milestone Apr 27, 2014
@jreback
Copy link
Contributor

jreback commented Apr 27, 2014

@sinhrks pls rebase (actually you might need to do most of your PR's as I merged one of them)

@jorisvandenbossche
Copy link
Member

@sinhrks For clarity: I am right the labels and colors keywords are keywords of the matplotlib's pie function, that are just passed to pie? (because otherwise I wouldn't be that fond of adding further new keywords to the already overlaoded pandas plot method)

(Cannot use ``label`` and ``color``, because of matplotlib's specification).
If you want to hide wedge labels, specify ``labels=None``.
If ``fontsize`` is specified, the value will be applied to wedge labels.
Also, other keywords supported by ``matplotlib.pyplot.pie`` can be used.
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 refer here by using :func:matplotlib.pyplot.pie``, then it will generate a link to its docs and you can directly inspect what other parameters you can use. Just need to add matplotlib in the list of intersphinx here (https://github.com/pydata/pandas/blob/master/doc/source/conf.py#L281)

@sinhrks
Copy link
Member Author

sinhrks commented Apr 28, 2014

Yep, labels and colors are derived from matplotlib.pyplot.pie. Also, I've modified the doc to link matplotlib.org.

@TomAugspurger
Copy link
Contributor

@jreback I'll reorganize plotting.rst before .14

@jreback
Copy link
Contributor

jreback commented Apr 28, 2014

gr8 thanks

@jreback
Copy link
Contributor

jreback commented May 1, 2014

@sinhrks @TomAugspurger

@TomAugspurger
Copy link
Contributor

Thanks @sinhrks. I retriggered the Travis build.

It's not great that we need to use colors instead of color here, but I agree that going with matplotlib's naming and documentation is the best way.

A nice feature would be to specify the layout if using subplots. But that can wait for another PR.

This should merge cleanly once the Travis is done.

@TomAugspurger
Copy link
Contributor

One more thing (not specific to this PR). Should we warn if a user passes an argument that we ignore in _args_adjust? Right now we just silently ignore it (I think).

@sinhrks
Copy link
Member Author

sinhrks commented May 5, 2014

@TomAugspurger Yes, it is better. Is it OK to show warnings only when explicitly change any options which collapses plot?

I mean, there are some options not used / not supported in Pie, such as secondary_y etc.

@TomAugspurger
Copy link
Contributor

I'm not sure what you mean by collapsing the plot. Do you mean like: s.pie(secondary_y=True)? I agree with what I think you're saying about only warning if a user explicitly changes from a default, and that change is ignored. But let's open a separate issue for this. The pie plot PR is good to go. Thanks.

TomAugspurger pushed a commit that referenced this pull request May 5, 2014
ENH: support pie plot in series and dataframe plot
@TomAugspurger TomAugspurger merged commit 49aece0 into pandas-dev:master May 5, 2014
@TomAugspurger
Copy link
Contributor

New issue for the warnings: #7045

@sinhrks sinhrks deleted the pie branch May 10, 2014 04:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants