Skip to content

Norm should be passed to facetgrid too #1160

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

Merged
merged 4 commits into from
Dec 9, 2016
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ Bug fixes
- Fixed sub-optimal performance in certain operations with object arrays (:issue:`1121`).
By `Yves Delley <https://github.com/burnpanck>`_.

- Fixed a bug whith facetgrid (the ``norm`` keyword was ignored, :issue:`1159`).
By `Fabien Maussion <https://github.com/fmaussion>`_.

.. _whats-new.0.8.2:

v0.8.2 (18 August 2016)
Expand Down
6 changes: 3 additions & 3 deletions xarray/plot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def _color_palette(cmap, n_colors):

def _determine_cmap_params(plot_data, vmin=None, vmax=None, cmap=None,
center=None, robust=False, extend=None,
levels=None, filled=True, cnorm=None):
levels=None, filled=True, norm=None):
"""
Use some heuristics to set good defaults for colorbar and range.

Expand Down Expand Up @@ -196,10 +196,10 @@ def _determine_cmap_params(plot_data, vmin=None, vmax=None, cmap=None,
extend = _determine_extend(calc_data, vmin, vmax)

if levels is not None:
cmap, cnorm = _build_discrete_cmap(cmap, levels, extend, filled)
cmap, norm = _build_discrete_cmap(cmap, levels, extend, filled)

return dict(vmin=vmin, vmax=vmax, cmap=cmap, extend=extend,
levels=levels, norm=cnorm)
levels=levels, norm=norm)


def _infer_xy_labels(darray, x, y):
Expand Down
11 changes: 9 additions & 2 deletions xarray/test/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ class TestPlot1D(PlotTestCase):

def setUp(self):
d = [0, 1.1, 0, 2]
self.darray = DataArray(d, coords={'period': range(len(d))})
self.darray = DataArray(d, coords={'period': range(len(d))},
dims='period')

def test_xlabel_is_index_name(self):
self.darray.plot()
Expand All @@ -206,7 +207,8 @@ def test_can_pass_in_axis(self):
self.pass_in_axis(self.darray.plot.line)

def test_nonnumeric_index_raises_typeerror(self):
a = DataArray([1, 2, 3], {'letter': ['a', 'b', 'c']})
a = DataArray([1, 2, 3], {'letter': ['a', 'b', 'c']},
dims='letter')
with self.assertRaisesRegexp(TypeError, r'[Pp]lot'):
a.plot.line()

Expand Down Expand Up @@ -293,6 +295,11 @@ def test_center(self):
self.assertIsNone(cmap_params['levels'])
self.assertIsNone(cmap_params['norm'])

def test_norm(self):
cmap_params = _determine_cmap_params(self.data,
norm=mpl.colors.SymLogNorm(0.1))
self.assertIsNotNone(cmap_params['norm'])

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, we can test this without having to test a private function like _determine_cmap_params. We should be able to check that the facet grid subplots are using the correct norm.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! done

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can get rid of this test then.

def test_integer_levels(self):
data = self.data + 1
cmap_params = _determine_cmap_params(data, levels=5, vmin=0, vmax=5,
Expand Down