Skip to content

Commit

Permalink
Merge pull request #1 from shoyer/facet2
Browse files Browse the repository at this point in the history
Colorbar positioning tweak and use tight_layout()
  • Loading branch information
clarkfitzg committed Sep 3, 2015
2 parents 78c584d + eab83a5 commit 1043bd2
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions xray/plot/facetgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class FacetGrid(object):
The basic workflow is to initialize the :class:`FacetGrid` object with
the DataArray and the variable names that are used to structure the grid. Then
one or more plotting functions can be applied to each subset by calling
:meth:`FacetGrid.map_dataarray` or :meth:`FacetGrid.map`.
:meth:`FacetGrid.map_dataarray` or :meth:`FacetGrid.map`.
Attributes
----------
Expand All @@ -78,7 +78,7 @@ def __init__(self, darray, col=None, row=None, col_wrap=None,
xray DataArray to be plotted
row, col : strings
Dimesion names that define subsets of the data, which will be drawn on
separate facets in the grid.
separate facets in the grid.
col_wrap : int, optional
"Wrap" the column variable at this width, so that the column facets
aspect : scalar, optional
Expand Down Expand Up @@ -257,19 +257,23 @@ def map_dataarray(self, plotfunc, x, y, max_xticks=4, max_yticks=4,
for ax in self.axes[-1, :]:
ax.set_xlabel(self.x)

# colorbar
if kwargs.get('add_colorbar', True):
self.fig.tight_layout()

self.fig.subplots_adjust(right=0.8)
if self._single_group:
for d, ax in zip(self.name_dicts.flat, self.axes.flat):
if d is None:
ax.set_visible(False)

cbar_ax = self.fig.add_axes([0.85, 0.15, 0.05, 0.7])
cbar = self.fig.colorbar(mappable, cax=cbar_ax,
extend=cmap_params['extend'])
# colorbar
if kwargs.get('add_colorbar', True):
cbar = self.fig.colorbar(mappable,
ax=list(self.axes.flat),
extend=cmap_params['extend'])

if self.darray.name:
cbar.set_label(self.darray.name, rotation=270,
verticalalignment='bottom')

# This happens here rather than __init__ since FacetGrid.map should
# use default ticks
self.set_ticks(max_xticks, max_yticks, fontsize)
Expand Down Expand Up @@ -307,13 +311,11 @@ def set_titles(self, template="{coord} = {value}", maxchar=30,

if self._single_group:
for d, ax in zip(self.name_dicts.flat, self.axes.flat):
# Only plot the ones with data
# Only label the ones with data
if d is not None:
coord, value = list(d.items()).pop()
title = nicetitle(coord, value, maxchar=maxchar)
ax.set_title(title, **kwargs)
else:
ax.set_visible(False)
else:
# The row titles on the right edge of the grid
if self._margin_titles:
Expand All @@ -333,7 +335,7 @@ def set_ticks(self, max_xticks=_NTICKS, max_yticks=_NTICKS, fontsize=_FONTSIZE):
'''
Sets tick behavior.
Refer to documentation in :meth:`FacetGrid.map_dataarray`
Refer to documentation in :meth:`FacetGrid.map_dataarray`
'''
from matplotlib.ticker import MaxNLocator

Expand Down

0 comments on commit 1043bd2

Please sign in to comment.