You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The ``rplot`` trellis plotting interface is deprecated and will be removed
1613
-
in a future version. We refer to external packages like
1612
+
The ``rplot`` trellis plotting interface is **deprecated and will be removed
1613
+
in a future version**. We refer to external packages like
1614
1614
`seaborn <https://github.com/mwaskom/seaborn>`_ for similar but more
1615
1615
refined functionality.
1616
1616
1617
1617
The docs below include some example on how to convert your existing code to
1618
-
these packages.
1618
+
``seaborn``.
1619
1619
1620
1620
.. ipython:: python
1621
1621
:suppress:
@@ -1657,7 +1657,13 @@ We import the rplot API:
1657
1657
Examples
1658
1658
~~~~~~~~
1659
1659
1660
-
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
+
1661
1667
1662
1668
.. ipython:: python
1663
1669
@@ -1675,7 +1681,20 @@ RPlot is a flexible API for producing Trellis plots. These plots allow you to ar
1675
1681
1676
1682
plt.close('all')
1677
1683
1678
-
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.
1679
1698
1680
1699
.. ipython:: python
1681
1700
@@ -1693,7 +1712,15 @@ In the example above, data from the tips data set is arranged by the attributes
1693
1712
1694
1713
plt.close('all')
1695
1714
1696
-
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.
1697
1724
1698
1725
.. ipython:: python
1699
1726
@@ -1712,7 +1739,27 @@ Example above is the same as previous except the plot is set to kernel density e
1712
1739
1713
1740
plt.close('all')
1714
1741
1715
-
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:
1716
1763
1717
1764
.. ipython:: python
1718
1765
@@ -1731,7 +1778,17 @@ The plot above shows that it is possible to have two or more plots for the same
1731
1778
1732
1779
plt.close('all')
1733
1780
1734
-
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.
1735
1792
1736
1793
.. ipython:: python
1737
1794
@@ -1749,7 +1806,7 @@ Above is a similar plot but with 2D kernel density estimation plot superimposed.
1749
1806
1750
1807
plt.close('all')
1751
1808
1752
-
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.
1753
1810
1754
1811
.. ipython:: python
1755
1812
@@ -1767,16 +1824,18 @@ It is possible to only use one attribute for grouping data. The example above on
1767
1824
1768
1825
plt.close('all')
1769
1826
1770
-
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.
@@ -1789,38 +1848,12 @@ If the first grouping attribute is not specified the plots will be arranged in a
1789
1848
1790
1849
plt.close('all')
1791
1850
1792
-
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.
1793
-
1794
-
1795
-
Scales
1796
-
~~~~~~
1797
-
1798
-
::
1799
-
1800
-
ScaleGradient(column, colour1, colour2)
1801
-
1802
-
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.
1803
-
1804
-
::
1805
-
1806
-
ScaleGradient2(column, colour1, colour2, colour3)
1807
-
1808
-
The same as ScaleGradient but interpolates linearly between three colours instead of two.
1809
-
1810
-
::
1811
-
1812
-
ScaleSize(column, min_size, max_size, transform)
1813
-
1814
-
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).
1815
-
1816
-
::
1817
-
1818
-
ScaleShape(column)
1819
-
1820
-
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:
1821
1852
1822
-
::
1853
+
.. code-block:: python
1823
1854
1824
-
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()
1825
1858
1826
-
Assign a random colour to a value of categorical attribute specified by column.
0 commit comments