-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: plot method accessors #9321
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 all commits
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{{ fullname }} | ||
{{ underline }} | ||
|
||
.. currentmodule:: {{ module.split('.')[0] }} | ||
|
||
.. autoaccessorcallable:: {{ [module.split('.')[1], objname]|join('.') }}.__call__ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ users upgrade to this version. | |
Highlights include: | ||
|
||
- Release the Global Interpreter Lock (GIL) on some cython operations, see :ref:`here <whatsnew_0170.gil>` | ||
- Plotting methods are now available as attributes of the ``.plot`` accessor, see :ref:`here <whatsnew_0170.plot>` | ||
- The sorting API has been revamped to remove some long-time inconsistencies, see :ref:`here <whatsnew_0170.api_breaking.sorting>` | ||
- Support for a ``datetime64[ns]`` with timezones as a first-class dtype, see :ref:`here <whatsnew_0170.tz>` | ||
- The default for ``to_datetime`` will now be to ``raise`` when presented with unparseable formats, | ||
|
@@ -116,6 +117,35 @@ Releasing of the GIL could benefit an application that uses threads for user int | |
.. _dask: https://dask.readthedocs.org/en/latest/ | ||
.. _QT: https://wiki.python.org/moin/PyQt | ||
|
||
.. _whatsnew_0170.plot: | ||
|
||
Plot submethods | ||
^^^^^^^^^^^^^^^ | ||
|
||
The Series and DataFrame ``.plot()`` method allows for customizing :ref:`plot types<visualization.other>` by supplying the ``kind`` keyword arguments. Unfortunately, many of these kinds of plots use different required and optional keyword arguments, which makes it difficult to discover what any given plot kind uses out of the dozens of possible arguments. | ||
|
||
To alleviate this issue, we have added a new, optional plotting interface, which exposes each kind of plot as a method of the ``.plot`` attribute. Instead of writing ``series.plot(kind=<kind>, ...)``, you can now also use ``series.plot.<kind>(...)``: | ||
|
||
.. ipython:: | ||
:verbatim: | ||
|
||
In [13]: df = pd.DataFrame(np.random.rand(10, 2), columns=['a', 'b']) | ||
|
||
In [14]: df.plot.bar() | ||
|
||
.. image:: _static/whatsnew_plot_submethods.png | ||
|
||
As a result of this change, these methods are now all discoverable via tab-completion: | ||
|
||
.. ipython:: | ||
:verbatim: | ||
|
||
In [15]: df.plot.<TAB> | ||
df.plot.area df.plot.barh df.plot.density df.plot.hist df.plot.line df.plot.scatter | ||
df.plot.bar df.plot.box df.plot.hexbin df.plot.kde df.plot.pie | ||
|
||
Each method signature only includes relevant arguments. Currently, these are limited to required arguments, but in the future these will include optional arguments, as well. For an overview, see the new :ref:`api.dataframe.plotting` API documentation. | ||
|
||
.. _whatsnew_0170.strftime: | ||
|
||
Support strftime for Datetimelikes | ||
|
@@ -251,7 +281,6 @@ has been changed to make this keyword unnecessary - the change is shown below. | |
Excel files saved in version 0.16.2 or prior that had index names will still able to be read in, | ||
but the ``has_index_names`` argument must specified to ``True``. | ||
|
||
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. couple of examples in a code-block maybe? (and maybe an ipython tab completion example) 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. Those are good ideas, I'll update, and probably add tab-completion to the plotting docs -- I had forgotten about that. |
||
|
||
.. _whatsnew_0170.enhancements.other: | ||
|
||
Other enhancements | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,13 +47,14 @@ | |
OrderedDict, raise_with_traceback) | ||
from pandas import compat | ||
from pandas.sparse.array import SparseArray | ||
from pandas.util.decorators import deprecate, Appender, Substitution, \ | ||
deprecate_kwarg | ||
from pandas.util.decorators import (cache_readonly, deprecate, Appender, | ||
Substitution, deprecate_kwarg) | ||
|
||
from pandas.tseries.period import PeriodIndex | ||
from pandas.tseries.index import DatetimeIndex | ||
|
||
import pandas.core.algorithms as algos | ||
import pandas.core.base as base | ||
import pandas.core.common as com | ||
import pandas.core.format as fmt | ||
import pandas.core.nanops as nanops | ||
|
@@ -5432,7 +5433,7 @@ def _put_str(s, space): | |
|
||
import pandas.tools.plotting as gfx | ||
|
||
DataFrame.plot = gfx.plot_frame | ||
DataFrame.plot = base.AccessorProperty(gfx.FramePlotMethods, gfx.FramePlotMethods) | ||
DataFrame.hist = gfx.hist_frame | ||
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. hmm, maybe we should deprecate 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 defaults on |
||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2882,7 +2882,7 @@ def __init__(self, *args, **kwargs): | |
|
||
import pandas.tools.plotting as _gfx | ||
|
||
Series.plot = _gfx.plot_series | ||
Series.plot = base.AccessorProperty(_gfx.SeriesPlotMethods, _gfx.SeriesPlotMethods) | ||
Series.hist = _gfx.hist_series | ||
|
||
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. deprecate |
||
# Add arithmetic! | ||
|
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.
I would add to the highlites a pointer to this section.
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.
done