Skip to content

Commit

Permalink
Allowed redrawing colorbars without passing arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Aug 21, 2016
1 parent 465e345 commit 328b34f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
5 changes: 4 additions & 1 deletion holoviews/plotting/mpl/chart3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ def _finalize_axis(self, key, **kwargs):
return super(Plot3D, self)._finalize_axis(key, **kwargs)


def _draw_colorbar(self, artist, element, dim=None):
def _draw_colorbar(self, dim=None):
element = self.hmap.last
artist = self.handles.get('artist', None)

fig = self.handles['fig']
ax = self.handles['axis']
# Get colorbar label
Expand Down
14 changes: 8 additions & 6 deletions holoviews/plotting/mpl/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,21 +553,23 @@ def _adjust_cbar(self, cbar, label, dim):


def _finalize_artist(self, key):
element = self.hmap.last
artist = self.handles.get('artist', None)
if artist and self.colorbar:
self._draw_colorbar(artist, element)
self._draw_colorbar()


def _draw_colorbar(self, artist, element, dim=None):
def _draw_colorbar(self, dim=None, redraw=True):
element = self.hmap.last
artist = self.handles.get('artist', None)
fig = self.handles['fig']
axis = self.handles['axis']
ax_colorbars, position = ColorbarPlot._colorbars.get(id(axis), ([], None))
specs = [spec[:2] for _, _, spec, _ in ax_colorbars]
spec = util.get_spec(element)

if position is None:
fig.canvas.draw()
if position is None or not redraw:
if redraw:
fig.canvas.draw()
bbox = axis.get_position()
l, b, w, h = bbox.x0, bbox.y0, bbox.width, bbox.height
else:
Expand All @@ -594,7 +596,7 @@ def _draw_colorbar(self, artist, element, dim=None):
self.handles['bbox_extra_artists'] += [cax, ylabel]
ax_colorbars.append((artist, cax, spec, label))

for i, (artist, cax, spec, label) in enumerate(ax_colorbars[:-1]):
for i, (artist, cax, spec, label) in enumerate(ax_colorbars):
scaled_w = w*width
cax.set_position([l+w+padding+(scaled_w+padding+w*0.15)*i,
b, scaled_w, h])
Expand Down
2 changes: 1 addition & 1 deletion holoviews/plotting/mpl/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def init_artists(self, ax, plot_args, plot_kwargs):
collection = PatchCollection(*plot_args, **plot_kwargs)
ax.add_collection(collection)
if self.colorbar:
self._draw_colorbar(collection, self.current_frame)
self._draw_colorbar()
return {'artist': collection, 'polys': plot_args[0]}


Expand Down

0 comments on commit 328b34f

Please sign in to comment.