Skip to content

Commit f71d811

Browse files
Merge pull request #9357 from jorisvandenbossche/rplot
Deprecating the trellis rplot module (GH3445)
2 parents 7e3212e + fb12f01 commit f71d811

9 files changed

+114
-45
lines changed
12.9 KB
Loading
30.6 KB
Loading
19 KB
Loading
30.4 KB
Loading
54.3 KB
Loading
26 KB
Loading

doc/source/visualization.rst

+87-44
Original file line numberDiff line numberDiff line change
@@ -1607,6 +1607,16 @@ when plotting a large number of points.
16071607
Trellis plotting interface
16081608
--------------------------
16091609

1610+
.. warning::
1611+
1612+
The ``rplot`` trellis plotting interface is **deprecated and will be removed
1613+
in a future version**. We refer to external packages like
1614+
`seaborn <https://github.com/mwaskom/seaborn>`_ for similar but more
1615+
refined functionality.
1616+
1617+
The docs below include some example on how to convert your existing code to
1618+
``seaborn``.
1619+
16101620
.. ipython:: python
16111621
:suppress:
16121622
@@ -1622,7 +1632,6 @@ Trellis plotting interface
16221632
iris_data = read_csv('data/iris.data')
16231633
from pandas import read_csv
16241634
from pandas.tools.plotting import radviz
1625-
import pandas.tools.rplot as rplot
16261635
plt.close('all')
16271636
16281637
@@ -1641,13 +1650,20 @@ Trellis plotting interface
16411650
We import the rplot API:
16421651

16431652
.. ipython:: python
1653+
:okwarning:
16441654
16451655
import pandas.tools.rplot as rplot
16461656
16471657
Examples
16481658
~~~~~~~~
16491659

1650-
RPlot is a flexible API for producing Trellis plots. These plots allow you to arrange data in a rectangular grid by values of certain attributes.
1660+
RPlot was an API for producing Trellis plots. These plots allow you toµ
1661+
arrange data in a rectangular grid by values of certain attributes.
1662+
In the example below, data from the tips data set is arranged by the attributes
1663+
'sex' and 'smoker'. Since both of those attributes can take on one of two
1664+
values, the resulting grid has two columns and two rows. A histogram is
1665+
displayed for each cell of the grid.
1666+
16511667

16521668
.. ipython:: python
16531669
@@ -1665,7 +1681,20 @@ RPlot is a flexible API for producing Trellis plots. These plots allow you to ar
16651681
16661682
plt.close('all')
16671683
1668-
In the example above, data from the tips data set is arranged by the attributes 'sex' and 'smoker'. Since both of those attributes can take on one of two values, the resulting grid has two columns and two rows. A histogram is displayed for each cell of the grid.
1684+
A similar plot can be made with ``seaborn`` using the ``FacetGrid`` object,
1685+
resulting in the following image:
1686+
1687+
.. code-block:: python
1688+
1689+
import seaborn as sns
1690+
g = sns.FacetGrid(tips_data, row="sex", col="smoker")
1691+
g.map(plt.hist, "total_bill")
1692+
1693+
.. image:: _static/rplot-seaborn-example1.png
1694+
1695+
1696+
Example below is the same as previous except the plot is set to kernel density
1697+
estimation. A ``seaborn`` example is included beneath.
16691698

16701699
.. ipython:: python
16711700
@@ -1683,7 +1712,15 @@ In the example above, data from the tips data set is arranged by the attributes
16831712
16841713
plt.close('all')
16851714
1686-
Example above is the same as previous except the plot is set to kernel density estimation. This shows how easy it is to have different plots for the same Trellis structure.
1715+
.. code-block:: python
1716+
1717+
g = sns.FacetGrid(tips_data, row="sex", col="smoker")
1718+
g.map(sns.kdeplot, "total_bill")
1719+
1720+
.. image:: _static/rplot-seaborn-example2.png
1721+
1722+
The plot below shows that it is possible to have two or more plots for the same
1723+
data displayed on the same Trellis grid cell.
16871724

16881725
.. ipython:: python
16891726
@@ -1702,7 +1739,27 @@ Example above is the same as previous except the plot is set to kernel density e
17021739
17031740
plt.close('all')
17041741
1705-
The plot above shows that it is possible to have two or more plots for the same data displayed on the same Trellis grid cell.
1742+
A seaborn equivalent for a simple scatter plot:
1743+
1744+
.. code-block:: python
1745+
1746+
g = sns.FacetGrid(tips_data, row="sex", col="smoker")
1747+
g.map(plt.scatter, "total_bill", "tip")
1748+
1749+
.. image:: _static/rplot-seaborn-example3.png
1750+
1751+
and with a regression line, using the dedicated ``seaborn`` ``regplot`` function:
1752+
1753+
.. code-block:: python
1754+
1755+
g = sns.FacetGrid(tips_data, row="sex", col="smoker", margin_titles=True)
1756+
g.map(sns.regplot, "total_bill", "tip", order=2)
1757+
1758+
.. image:: _static/rplot-seaborn-example3b.png
1759+
1760+
1761+
Below is a similar plot but with 2D kernel density estimation plot superimposed,
1762+
followed by a ``seaborn`` equivalent:
17061763

17071764
.. ipython:: python
17081765
@@ -1721,7 +1778,17 @@ The plot above shows that it is possible to have two or more plots for the same
17211778
17221779
plt.close('all')
17231780
1724-
Above is a similar plot but with 2D kernel density estimation plot superimposed.
1781+
.. code-block:: python
1782+
1783+
g = sns.FacetGrid(tips_data, row="sex", col="smoker")
1784+
g.map(plt.scatter, "total_bill", "tip")
1785+
g.map(sns.kdeplot, "total_bill", "tip")
1786+
1787+
.. image:: _static/rplot-seaborn-example4.png
1788+
1789+
It is possible to only use one attribute for grouping data. The example above
1790+
only uses 'sex' attribute. If the second grouping attribute is not specified,
1791+
the plots will be arranged in a column.
17251792

17261793
.. ipython:: python
17271794
@@ -1739,7 +1806,7 @@ Above is a similar plot but with 2D kernel density estimation plot superimposed.
17391806
17401807
plt.close('all')
17411808
1742-
It is possible to only use one attribute for grouping data. The example above only uses 'sex' attribute. If the second grouping attribute is not specified, the plots will be arranged in a column.
1809+
If the first grouping attribute is not specified the plots will be arranged in a row.
17431810

17441811
.. ipython:: python
17451812
@@ -1757,16 +1824,18 @@ It is possible to only use one attribute for grouping data. The example above on
17571824
17581825
plt.close('all')
17591826
1760-
If the first grouping attribute is not specified the plots will be arranged in a row.
1827+
In ``seaborn``, this can also be done by only specifying one of the ``row``
1828+
and ``col`` arguments.
1829+
1830+
In the example below the colour and shape of the scatter plot graphical
1831+
objects is mapped to 'day' and 'size' attributes respectively. You use
1832+
scale objects to specify these mappings. The list of scale classes is
1833+
given below with initialization arguments for quick reference.
17611834

17621835
.. ipython:: python
17631836
17641837
plt.figure()
17651838
1766-
plot = rplot.RPlot(tips_data, x='total_bill', y='tip')
1767-
plot.add(rplot.TrellisGrid(['.', 'smoker']))
1768-
plot.add(rplot.GeomHistogram())
1769-
17701839
plot = rplot.RPlot(tips_data, x='tip', y='total_bill')
17711840
plot.add(rplot.TrellisGrid(['sex', 'smoker']))
17721841
plot.add(rplot.GeomPoint(size=80.0, colour=rplot.ScaleRandomColour('day'), shape=rplot.ScaleShape('size'), alpha=1.0))
@@ -1779,38 +1848,12 @@ If the first grouping attribute is not specified the plots will be arranged in a
17791848
17801849
plt.close('all')
17811850
1782-
As shown above, scatter plots are also possible. Scatter plots allow you to map various data attributes to graphical properties of the plot. In the example above the colour and shape of the scatter plot graphical objects is mapped to 'day' and 'size' attributes respectively. You use scale objects to specify these mappings. The list of scale classes is given below with initialization arguments for quick reference.
1783-
1784-
1785-
Scales
1786-
~~~~~~
1787-
1788-
::
1789-
1790-
ScaleGradient(column, colour1, colour2)
1791-
1792-
This one allows you to map an attribute (specified by parameter column) value to the colour of a graphical object. The larger the value of the attribute the closer the colour will be to colour2, the smaller the value, the closer it will be to colour1.
1793-
1794-
::
1795-
1796-
ScaleGradient2(column, colour1, colour2, colour3)
1797-
1798-
The same as ScaleGradient but interpolates linearly between three colours instead of two.
1799-
1800-
::
1801-
1802-
ScaleSize(column, min_size, max_size, transform)
1803-
1804-
Map attribute value to size of the graphical object. Parameter min_size (default 5.0) is the minimum size of the graphical object, max_size (default 100.0) is the maximum size and transform is a one argument function that will be used to transform the attribute value (defaults to lambda x: x).
1805-
1806-
::
1807-
1808-
ScaleShape(column)
1809-
1810-
Map the shape of the object to attribute value. The attribute has to be categorical.
1851+
This can also be done in ``seaborn``, at least for 3 variables:
18111852

1812-
::
1853+
.. code-block:: python
18131854
1814-
ScaleRandomColour(column)
1855+
g = sns.FacetGrid(tips_data, row="sex", col="smoker", hue="day")
1856+
g.map(plt.scatter, "tip", "total_bill")
1857+
g.add_legend()
18151858
1816-
Assign a random colour to a value of categorical attribute specified by column.
1859+
.. image:: _static/rplot-seaborn-example6.png

doc/source/whatsnew/v0.16.0.txt

+16-1
Original file line numberDiff line numberDiff line change
@@ -365,10 +365,25 @@ The behavior of a small sub-set of edge cases for using ``.loc`` have changed (:
365365
In [4]: df.loc[2:3]
366366
TypeError: Cannot do slice indexing on <class 'pandas.tseries.index.DatetimeIndex'> with <type 'int'> keys
367367

368+
369+
.. _whatsnew_0160.deprecations:
370+
368371
Deprecations
369372
~~~~~~~~~~~~
370373

371-
.. _whatsnew_0160.deprecations:
374+
- The ``rplot`` trellis plotting interface is deprecated and will be removed
375+
in a future version. We refer to external packages like
376+
`seaborn <http://stanford.edu/~mwaskom/software/seaborn/>`_ for similar
377+
but more refined functionality (:issue:`3445`).
378+
379+
The documentation includes some examples how to convert your existing code
380+
using ``rplot`` to seaborn: - :ref:`rplot docs <rplot>`
381+
382+
383+
.. _whatsnew_0160.prior_deprecations:
384+
385+
Removal of prior version deprecations/changes
386+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
372387

373388
- ``DataFrame.pivot_table`` and ``crosstab``'s ``rows`` and ``cols`` keyword arguments were removed in favor
374389
of ``index`` and ``columns`` (:issue:`6581`)

pandas/tools/rplot.py

+11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import random
2+
import warnings
23
from copy import deepcopy
34
from pandas.core.common import _values_from_object
45

@@ -9,6 +10,16 @@
910
# * Make sure legends work properly
1011
#
1112

13+
14+
warnings.warn("\n"
15+
"The rplot trellis plotting interface is deprecated and will be "
16+
"removed in a future version. We refer to external packages "
17+
"like seaborn for similar but more refined functionality. \n\n"
18+
"See our docs http://pandas.pydata.org/pandas-docs/stable/visualization.html#rplot "
19+
"for some example how to convert your existing code to these "
20+
"packages.", FutureWarning)
21+
22+
1223
class Scale:
1324
"""
1425
Base class for mapping between graphical and data attributes.

0 commit comments

Comments
 (0)