Skip to content

Commit 7993fc8

Browse files
jorisvandenbosschejreback
authored andcommitted
CLN/API: move plotting funcs to pandas.plotting (#16005)
closes #12548
1 parent 413e2c6 commit 7993fc8

30 files changed

+5696
-5489
lines changed

doc/source/visualization.rst

+14-14
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ You can also create these other plots using the methods ``DataFrame.plot.<kind>`
152152
In addition to these ``kind`` s, there are the :ref:`DataFrame.hist() <visualization.hist>`,
153153
and :ref:`DataFrame.boxplot() <visualization.box>` methods, which use a separate interface.
154154

155-
Finally, there are several :ref:`plotting functions <visualization.tools>` in ``pandas.tools.plotting``
155+
Finally, there are several :ref:`plotting functions <visualization.tools>` in ``pandas.plotting``
156156
that take a :class:`Series` or :class:`DataFrame` as an argument. These
157157
include
158158

@@ -823,7 +823,7 @@ before plotting.
823823
Plotting Tools
824824
--------------
825825

826-
These functions can be imported from ``pandas.tools.plotting``
826+
These functions can be imported from ``pandas.plotting``
827827
and take a :class:`Series` or :class:`DataFrame` as an argument.
828828

829829
.. _visualization.scatter_matrix:
@@ -834,7 +834,7 @@ Scatter Matrix Plot
834834
.. versionadded:: 0.7.3
835835

836836
You can create a scatter plot matrix using the
837-
``scatter_matrix`` method in ``pandas.tools.plotting``:
837+
``scatter_matrix`` method in ``pandas.plotting``:
838838

839839
.. ipython:: python
840840
:suppress:
@@ -843,7 +843,7 @@ You can create a scatter plot matrix using the
843843
844844
.. ipython:: python
845845
846-
from pandas.tools.plotting import scatter_matrix
846+
from pandas.plotting import scatter_matrix
847847
df = pd.DataFrame(np.random.randn(1000, 4), columns=['a', 'b', 'c', 'd'])
848848
849849
@savefig scatter_matrix_kde.png
@@ -896,7 +896,7 @@ of the same class will usually be closer together and form larger structures.
896896

897897
.. ipython:: python
898898
899-
from pandas.tools.plotting import andrews_curves
899+
from pandas.plotting import andrews_curves
900900
901901
data = pd.read_csv('data/iris.data')
902902
@@ -918,7 +918,7 @@ represents one data point. Points that tend to cluster will appear closer togeth
918918

919919
.. ipython:: python
920920
921-
from pandas.tools.plotting import parallel_coordinates
921+
from pandas.plotting import parallel_coordinates
922922
923923
data = pd.read_csv('data/iris.data')
924924
@@ -948,7 +948,7 @@ implies that the underlying data are not random.
948948
949949
.. ipython:: python
950950
951-
from pandas.tools.plotting import lag_plot
951+
from pandas.plotting import lag_plot
952952
953953
plt.figure()
954954
@@ -983,7 +983,7 @@ confidence band.
983983
984984
.. ipython:: python
985985
986-
from pandas.tools.plotting import autocorrelation_plot
986+
from pandas.plotting import autocorrelation_plot
987987
988988
plt.figure()
989989
@@ -1016,7 +1016,7 @@ are what constitutes the bootstrap plot.
10161016
10171017
.. ipython:: python
10181018
1019-
from pandas.tools.plotting import bootstrap_plot
1019+
from pandas.plotting import bootstrap_plot
10201020
10211021
data = pd.Series(np.random.rand(1000))
10221022
@@ -1048,7 +1048,7 @@ be colored differently.
10481048

10491049
.. ipython:: python
10501050
1051-
from pandas.tools.plotting import radviz
1051+
from pandas.plotting import radviz
10521052
10531053
data = pd.read_csv('data/iris.data')
10541054
@@ -1228,14 +1228,14 @@ Using the ``x_compat`` parameter, you can suppress this behavior:
12281228
plt.close('all')
12291229
12301230
If you have more than one plot that needs to be suppressed, the ``use`` method
1231-
in ``pandas.plot_params`` can be used in a `with statement`:
1231+
in ``pandas.plotting.plot_params`` can be used in a `with statement`:
12321232

12331233
.. ipython:: python
12341234
12351235
plt.figure()
12361236
12371237
@savefig ser_plot_suppress_context.png
1238-
with pd.plot_params.use('x_compat', True):
1238+
with pd.plotting.plot_params.use('x_compat', True):
12391239
df.A.plot(color='r')
12401240
df.B.plot(color='g')
12411241
df.C.plot(color='b')
@@ -1450,11 +1450,11 @@ Also, you can pass different :class:`DataFrame` or :class:`Series` for ``table``
14501450
14511451
plt.close('all')
14521452
1453-
Finally, there is a helper function ``pandas.tools.plotting.table`` to create a table from :class:`DataFrame` and :class:`Series`, and add it to an ``matplotlib.Axes``. This function can accept keywords which matplotlib table has.
1453+
Finally, there is a helper function ``pandas.plotting.table`` to create a table from :class:`DataFrame` and :class:`Series`, and add it to an ``matplotlib.Axes``. This function can accept keywords which matplotlib table has.
14541454

14551455
.. ipython:: python
14561456
1457-
from pandas.tools.plotting import table
1457+
from pandas.plotting import table
14581458
fig, ax = plt.subplots(1, 1)
14591459
14601460
table(ax, np.round(df.describe(), 2),

doc/source/whatsnew/v0.20.0.txt

+26
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Highlights include:
2121
- Support for S3 handling now uses ``s3fs``, see :ref:`here <whatsnew_0200.api_breaking.s3>`
2222
- Google BigQuery support now uses the ``pandas-gbq`` library, see :ref:`here <whatsnew_0200.api_breaking.gbq>`
2323
- Switched the test framework to use `pytest <http://doc.pytest.org/en/latest>`__ (:issue:`13097`)
24+
- The ``pandas.tools.plotting`` module has been deprecated, moved to ``pandas.plotting``. See :ref:`here <whatsnew_0200.api_breaking.plotting>`
2425

2526

2627
Check the :ref:`API Changes <whatsnew_0200.api_breaking>` and :ref:`deprecations <whatsnew_0200.deprecations>` before updating.
@@ -557,6 +558,31 @@ Using ``.iloc``. Here we will get the location of the 'A' column, then use *posi
557558
df.iloc[[0, 2], df.columns.get_loc('A')]
558559

559560

561+
.. _whatsnew_0200.api_breaking.deprecate_plotting
562+
563+
Deprecate .plotting
564+
^^^^^^^^^^^^^^^^^^^
565+
566+
The ``pandas.tools.plotting`` module has been deprecated, in favor of the top level ``pandas.plotting`` module. All the public plotting functions are now available
567+
from ``pandas.plotting`` (:issue:`12548`).
568+
569+
Furthermore, the top-level ``pandas.scatter_matrix`` and ``pandas.plot_params`` are deprecated.
570+
Users can import these from ``pandas.plotting`` as well.
571+
572+
Previous script:
573+
574+
.. code-block:: python
575+
576+
pd.tools.plotting.scatter_matrix(df)
577+
pd.scatter_matrix(df)
578+
579+
Should be changed to:
580+
581+
.. code-block:: python
582+
583+
pd.plotting.scatter_matrix(df)
584+
585+
560586
.. _whatsnew_0200.api_breaking.deprecate_panel:
561587

562588
Deprecate Panel

pandas/__init__.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,15 @@
4949
from pandas.tools.merge import (merge, ordered_merge,
5050
merge_ordered, merge_asof)
5151
from pandas.tools.pivot import pivot_table, crosstab
52-
from pandas.tools.plotting import scatter_matrix, plot_params
52+
53+
# deprecate tools.plotting, plot_params and scatter_matrix on the top namespace
54+
import pandas.tools.plotting
55+
plot_params = pandas.plotting._style._Options(deprecated=True)
56+
# do not import deprecate to top namespace
57+
scatter_matrix = pandas.util.decorators.deprecate(
58+
'pandas.scatter_matrix', pandas.plotting.scatter_matrix,
59+
'pandas.plotting.scatter_matrix')
60+
5361
from pandas.tools.tile import cut, qcut
5462
from pandas.tools.util import to_numeric
5563
from pandas.core.reshape import melt

pandas/core/config_init.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ def mpl_style_cb(key):
285285
stacklevel=5)
286286

287287
import sys
288-
from pandas.tools.plotting import mpl_stylesheet
288+
from pandas.plotting._style import mpl_stylesheet
289289
global style_backup
290290

291291
val = cf.get_option(key)

pandas/core/frame.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
import pandas.core.ops as ops
9191
import pandas.formats.format as fmt
9292
from pandas.formats.printing import pprint_thing
93-
import pandas.tools.plotting as gfx
93+
import pandas.plotting._core as gfx
9494

9595
from pandas._libs import lib, algos as libalgos
9696

@@ -5909,11 +5909,11 @@ def _put_str(s, space):
59095909
@Appender(_shared_docs['boxplot'] % _shared_doc_kwargs)
59105910
def boxplot(self, column=None, by=None, ax=None, fontsize=None, rot=0,
59115911
grid=True, figsize=None, layout=None, return_type=None, **kwds):
5912-
import pandas.tools.plotting as plots
5912+
from pandas.plotting._core import boxplot
59135913
import matplotlib.pyplot as plt
5914-
ax = plots.boxplot(self, column=column, by=by, ax=ax, fontsize=fontsize,
5915-
grid=grid, rot=rot, figsize=figsize, layout=layout,
5916-
return_type=return_type, **kwds)
5914+
ax = boxplot(self, column=column, by=by, ax=ax, fontsize=fontsize,
5915+
grid=grid, rot=rot, figsize=figsize, layout=layout,
5916+
return_type=return_type, **kwds)
59175917
plt.draw_if_interactive()
59185918
return ax
59195919

pandas/core/groupby.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4159,7 +4159,7 @@ def groupby_series(obj, col=None):
41594159
return results
41604160

41614161

4162-
from pandas.tools.plotting import boxplot_frame_groupby # noqa
4162+
from pandas.plotting._core import boxplot_frame_groupby # noqa
41634163
DataFrameGroupBy.boxplot = boxplot_frame_groupby
41644164

41654165

pandas/core/series.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3026,7 +3026,7 @@ def create_from_value(value, index, dtype):
30263026
# ----------------------------------------------------------------------
30273027
# Add plotting methods to Series
30283028

3029-
import pandas.tools.plotting as _gfx # noqa
3029+
import pandas.plotting._core as _gfx # noqa
30303030

30313031
Series.plot = base.AccessorProperty(_gfx.SeriesPlotMethods,
30323032
_gfx.SeriesPlotMethods)

pandas/plotting/__init__.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""
2+
Plotting api
3+
"""
4+
5+
# flake8: noqa
6+
7+
try: # mpl optional
8+
from pandas.plotting import _converter
9+
_converter.register() # needs to override so set_xlim works with str/number
10+
except ImportError:
11+
pass
12+
13+
from pandas.plotting._misc import (scatter_matrix, radviz,
14+
andrews_curves, bootstrap_plot,
15+
parallel_coordinates, lag_plot,
16+
autocorrelation_plot)
17+
from pandas.plotting._core import boxplot
18+
from pandas.plotting._style import plot_params
19+
from pandas.plotting._tools import table

pandas/plotting/_compat.py

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# being a bit too dynamic
2+
# pylint: disable=E1101
3+
from __future__ import division
4+
5+
from distutils.version import LooseVersion
6+
7+
8+
def _mpl_le_1_2_1():
9+
try:
10+
import matplotlib as mpl
11+
return (str(mpl.__version__) <= LooseVersion('1.2.1') and
12+
str(mpl.__version__)[0] != '0')
13+
except ImportError:
14+
return False
15+
16+
17+
def _mpl_ge_1_3_1():
18+
try:
19+
import matplotlib
20+
# The or v[0] == '0' is because their versioneer is
21+
# messed up on dev
22+
return (matplotlib.__version__ >= LooseVersion('1.3.1') or
23+
matplotlib.__version__[0] == '0')
24+
except ImportError:
25+
return False
26+
27+
28+
def _mpl_ge_1_4_0():
29+
try:
30+
import matplotlib
31+
return (matplotlib.__version__ >= LooseVersion('1.4') or
32+
matplotlib.__version__[0] == '0')
33+
except ImportError:
34+
return False
35+
36+
37+
def _mpl_ge_1_5_0():
38+
try:
39+
import matplotlib
40+
return (matplotlib.__version__ >= LooseVersion('1.5') or
41+
matplotlib.__version__[0] == '0')
42+
except ImportError:
43+
return False
44+
45+
46+
def _mpl_ge_2_0_0():
47+
try:
48+
import matplotlib
49+
return matplotlib.__version__ >= LooseVersion('2.0')
50+
except ImportError:
51+
return False
52+
53+
54+
def _mpl_le_2_0_0():
55+
try:
56+
import matplotlib
57+
return matplotlib.compare_versions('2.0.0', matplotlib.__version__)
58+
except ImportError:
59+
return False
60+
61+
62+
def _mpl_ge_2_0_1():
63+
try:
64+
import matplotlib
65+
return matplotlib.__version__ >= LooseVersion('2.0.1')
66+
except ImportError:
67+
return False

0 commit comments

Comments
 (0)