Skip to content

Commit 1043bd2

Browse files
committed
Merge pull request #1 from shoyer/facet2
Colorbar positioning tweak and use tight_layout()
2 parents 78c584d + eab83a5 commit 1043bd2

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

xray/plot/facetgrid.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class FacetGrid(object):
5353
The basic workflow is to initialize the :class:`FacetGrid` object with
5454
the DataArray and the variable names that are used to structure the grid. Then
5555
one or more plotting functions can be applied to each subset by calling
56-
:meth:`FacetGrid.map_dataarray` or :meth:`FacetGrid.map`.
56+
:meth:`FacetGrid.map_dataarray` or :meth:`FacetGrid.map`.
5757
5858
Attributes
5959
----------
@@ -78,7 +78,7 @@ def __init__(self, darray, col=None, row=None, col_wrap=None,
7878
xray DataArray to be plotted
7979
row, col : strings
8080
Dimesion names that define subsets of the data, which will be drawn on
81-
separate facets in the grid.
81+
separate facets in the grid.
8282
col_wrap : int, optional
8383
"Wrap" the column variable at this width, so that the column facets
8484
aspect : scalar, optional
@@ -257,19 +257,23 @@ def map_dataarray(self, plotfunc, x, y, max_xticks=4, max_yticks=4,
257257
for ax in self.axes[-1, :]:
258258
ax.set_xlabel(self.x)
259259

260-
# colorbar
261-
if kwargs.get('add_colorbar', True):
260+
self.fig.tight_layout()
262261

263-
self.fig.subplots_adjust(right=0.8)
262+
if self._single_group:
263+
for d, ax in zip(self.name_dicts.flat, self.axes.flat):
264+
if d is None:
265+
ax.set_visible(False)
264266

265-
cbar_ax = self.fig.add_axes([0.85, 0.15, 0.05, 0.7])
266-
cbar = self.fig.colorbar(mappable, cax=cbar_ax,
267-
extend=cmap_params['extend'])
267+
# colorbar
268+
if kwargs.get('add_colorbar', True):
269+
cbar = self.fig.colorbar(mappable,
270+
ax=list(self.axes.flat),
271+
extend=cmap_params['extend'])
268272

269273
if self.darray.name:
270274
cbar.set_label(self.darray.name, rotation=270,
271275
verticalalignment='bottom')
272-
276+
273277
# This happens here rather than __init__ since FacetGrid.map should
274278
# use default ticks
275279
self.set_ticks(max_xticks, max_yticks, fontsize)
@@ -307,13 +311,11 @@ def set_titles(self, template="{coord} = {value}", maxchar=30,
307311

308312
if self._single_group:
309313
for d, ax in zip(self.name_dicts.flat, self.axes.flat):
310-
# Only plot the ones with data
314+
# Only label the ones with data
311315
if d is not None:
312316
coord, value = list(d.items()).pop()
313317
title = nicetitle(coord, value, maxchar=maxchar)
314318
ax.set_title(title, **kwargs)
315-
else:
316-
ax.set_visible(False)
317319
else:
318320
# The row titles on the right edge of the grid
319321
if self._margin_titles:
@@ -333,7 +335,7 @@ def set_ticks(self, max_xticks=_NTICKS, max_yticks=_NTICKS, fontsize=_FONTSIZE):
333335
'''
334336
Sets tick behavior.
335337
336-
Refer to documentation in :meth:`FacetGrid.map_dataarray`
338+
Refer to documentation in :meth:`FacetGrid.map_dataarray`
337339
'''
338340
from matplotlib.ticker import MaxNLocator
339341

0 commit comments

Comments
 (0)