Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 6 additions & 3 deletions xarray/plot/facetgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,12 @@ def map(self, func, *args, **kwargs):
data = self.data.loc[namedict]
plt.sca(ax)
innerargs = [data[a].values for a in args]
# TODO: is it possible to verify that an artist is mappable?
mappable = func(*innerargs, **kwargs)
self._mappables.append(mappable)
maybe_mappable = func(*innerargs, **kwargs)
# TODO: better way to verify that an artist is mappable?
# https://stackoverflow.com/questions/33023036/is-it-possible-to-detect-if-a-matplotlib-artist-is-a-mappable-suitable-for-use-w#33023522
if (maybe_mappable and
hasattr(maybe_mappable, 'autoscale_None')):
self._mappables.append(maybe_mappable)

self._finalize_grid(*args[:2])

Expand Down
2 changes: 1 addition & 1 deletion xarray/plot/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ def newplotfunc(darray, x=None, y=None, figsize=None, size=None,
cbar_kwargs.setdefault('cax', cbar_ax)
cbar = plt.colorbar(primitive, **cbar_kwargs)
if add_labels and 'label' not in cbar_kwargs:
cbar.set_label(label_from_attrs(darray), rotation=90)
cbar.set_label(label_from_attrs(darray))
elif cbar_ax is not None or cbar_kwargs is not None:
# inform the user about keywords which aren't used
raise ValueError("cbar_ax and cbar_kwargs can't be used with "
Expand Down
3 changes: 2 additions & 1 deletion xarray/plot/utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from __future__ import absolute_import, division, print_function

import textwrap
import warnings

import numpy as np
import textwrap

from ..core.options import OPTIONS
from ..core.pycompat import basestring
from ..core.utils import is_scalar
from ..core.options import OPTIONS
Expand Down
13 changes: 13 additions & 0 deletions xarray/tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,19 @@ def test_convenient_facetgrid_4d(self):
for ax in g.axes.flat:
assert ax.has_data()

@pytest.mark.filterwarnings('ignore:This figure includes')
def test_facetgrid_map_only_appends_mappables(self):
a = easy_array((10, 15, 2, 3))
d = DataArray(a, dims=['y', 'x', 'columns', 'rows'])
g = self.plotfunc(d, x='x', y='y', col='columns', row='rows')

expected = g._mappables

g.map(lambda: plt.plot(1, 1))
actual = g._mappables

assert expected == actual

def test_facetgrid_cmap(self):
# Regression test for GH592
data = (np.random.random(size=(20, 25, 12)) + np.linspace(-3, 3, 12))
Expand Down