From 792950d5a11985b2a19a9ea6c03ceae09863472d Mon Sep 17 00:00:00 2001 From: mwaskom Date: Thu, 12 Mar 2015 23:12:06 -0700 Subject: [PATCH 1/3] Fix bug with FacetGrid ticklabels and col_wrap Closes #464 --- seaborn/axisgrid.py | 4 ++-- seaborn/tests/test_axisgrid.py | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/seaborn/axisgrid.py b/seaborn/axisgrid.py index 9146b8af6a..4c4ad43089 100644 --- a/seaborn/axisgrid.py +++ b/seaborn/axisgrid.py @@ -639,7 +639,7 @@ def set_ylabels(self, label=None, **kwargs): def set_xticklabels(self, labels=None, step=None, **kwargs): """Set x axis tick labels on the bottom row of the grid.""" - for ax in self.axes[-1, :]: + for ax in self._bottom_axes: if labels is None: labels = [l.get_text() for l in ax.get_xticklabels()] if step is not None: @@ -651,7 +651,7 @@ def set_xticklabels(self, labels=None, step=None, **kwargs): def set_yticklabels(self, labels=None, **kwargs): """Set y axis tick labels on the left column of the grid.""" - for ax in self.axes[-1, :]: + for ax in self._left_axes: if labels is None: labels = [l.get_text() for l in ax.get_yticklabels()] ax.set_yticklabels(labels, **kwargs) diff --git a/seaborn/tests/test_axisgrid.py b/seaborn/tests/test_axisgrid.py index ee4fee88dd..2ed76802d4 100644 --- a/seaborn/tests/test_axisgrid.py +++ b/seaborn/tests/test_axisgrid.py @@ -489,6 +489,18 @@ def test_set_ticklabels(self): got_x = [int(l.get_text()) for l in g.axes[0, 0].get_xticklabels()] npt.assert_array_equal(x[::2], got_x) + g = ag.FacetGrid(self.df, col="d", col_wrap=5) + g.map(plt.plot, "x", "y") + g.set_xticklabels(rotation=45) + g.set_yticklabels(rotation=75) + for ax in g._bottom_axes: + for l in ax.get_xticklabels(): + nt.assert_equal(l.get_rotation(), 45) + for ax in g._left_axes: + for l in ax.get_yticklabels(): + nt.assert_equal(l.get_rotation(), 75) + plt.close("all") + def test_set_axis_labels(self): g = ag.FacetGrid(self.df, row="a", col="b") @@ -502,6 +514,7 @@ def test_set_axis_labels(self): got_y = [ax.get_ylabel() for ax in g.axes[:, 0]] npt.assert_array_equal(got_x, xlab) npt.assert_array_equal(got_y, ylab) + plt.close("all") def test_axis_lims(self): From 7296bcfb3696f52f2d01b3c971cdb69902e1487a Mon Sep 17 00:00:00 2001 From: mwaskom Date: Thu, 12 Mar 2015 23:22:46 -0700 Subject: [PATCH 2/3] Raise a better error with `row` and `col_wrap` Closes #465 --- seaborn/axisgrid.py | 3 +++ seaborn/tests/test_axisgrid.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/seaborn/axisgrid.py b/seaborn/axisgrid.py index 4c4ad43089..6a8dd38803 100644 --- a/seaborn/axisgrid.py +++ b/seaborn/axisgrid.py @@ -249,6 +249,9 @@ def __init__(self, data, row=None, col=None, hue=None, col_wrap=None, self._col_wrap = col_wrap if col_wrap is not None: + if row is not None: + err = "Cannot use `row` and `col_wrap` together." + raise ValueError(err) ncol = col_wrap nrow = int(np.ceil(len(data[col].unique()) / col_wrap)) self._ncol = ncol diff --git a/seaborn/tests/test_axisgrid.py b/seaborn/tests/test_axisgrid.py index 2ed76802d4..9c3e8e1d29 100644 --- a/seaborn/tests/test_axisgrid.py +++ b/seaborn/tests/test_axisgrid.py @@ -104,6 +104,9 @@ def test_col_wrap(self): nt.assert_equal(g_wrap._ncol, 4) nt.assert_equal(g_wrap._nrow, 3) + with nt.assert_raises(ValueError): + g = ag.FacetGrid(self.df, row="b", col="d", col_wrap=4) + plt.close("all") def test_normal_axes(self): From 095aeb402d4eadf71267d73b898d9bf1ff83497b Mon Sep 17 00:00:00 2001 From: mwaskom Date: Thu, 12 Mar 2015 23:25:26 -0700 Subject: [PATCH 3/3] Update release notes --- doc/releases/v0.6.0.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/releases/v0.6.0.txt b/doc/releases/v0.6.0.txt index 5acc6de3e7..95a8dce13e 100644 --- a/doc/releases/v0.6.0.txt +++ b/doc/releases/v0.6.0.txt @@ -57,3 +57,5 @@ Bug fixes ~~~~~~~~~ - Fixed a bug in :class:`FacetGrid` and :class:`PairGrid` that lead to incorrect legend labels when levels of the ``hue`` variable appeared in ``hue_order`` but not in the data. + +- Fixed a bug in :meth:`FacetGrid.set_xticklabels` or :meth:`FacetGrid.set_yticklabels` when ``col_wrap`` is being used.