Skip to content

Commit

Permalink
Fontsize colorbar (#3914)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuang11 authored and philippjfr committed Aug 18, 2019
1 parent a461137 commit e0a1719
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
12 changes: 12 additions & 0 deletions holoviews/plotting/bokeh/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -1604,6 +1604,18 @@ def _draw_colorbar(self, plot, color_mapper, prefix=''):
if self.cformatter is not None:
self.colorbar_opts.update({'formatter': wrap_formatter(self.cformatter, 'c')})

for tk in ['cticks', 'ticks']:
ticksize = self._fontsize(tk, common=False).get('fontsize')
if ticksize is not None:
self.colorbar_opts.update({'major_label_text_font_size': ticksize})
break

for lb in ['clabel', 'labels']:
labelsize = self._fontsize(lb, common=False).get('fontsize')
if labelsize is not None:
self.colorbar_opts.update({'title_text_font_size': labelsize})
break

opts = dict(cbar_opts['opts'], color_mapper=color_mapper, ticker=ticker,
**self._colorbar_defaults)
color_bar = ColorBar(**dict(opts, **self.colorbar_opts))
Expand Down
14 changes: 13 additions & 1 deletion holoviews/plotting/mpl/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,9 +708,15 @@ def __init__(self, *args, **kwargs):

def _adjust_cbar(self, cbar, label, dim):
noalpha = math.floor(self.style[self.cyclic_index].get('alpha', 1)) == 1

for lb in ['clabel', 'labels']:
labelsize = self._fontsize(lb, common=False).get('fontsize')
if labelsize is not None:
break

if (cbar.solids and noalpha):
cbar.solids.set_edgecolor("face")
cbar.set_label(label)
cbar.set_label(label, fontsize=labelsize)
if isinstance(self.cbar_ticks, ticker.Locator):
cbar.ax.yaxis.set_major_locator(self.cbar_ticks)
elif self.cbar_ticks == 0:
Expand All @@ -727,6 +733,12 @@ def _adjust_cbar(self, cbar, label, dim):
cbar.set_ticks(ticks)
cbar.set_ticklabels(labels)

for tk in ['cticks', 'ticks']:
ticksize = self._fontsize(tk, common=False).get('fontsize')
if ticksize is not None:
cbar.ax.tick_params(labelsize=ticksize)
break


def _finalize_artist(self, element):
if self.colorbar:
Expand Down
8 changes: 4 additions & 4 deletions holoviews/plotting/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,8 @@ class DimensionedPlot(Plot):
together using the 'labels' key.""")

#Allowed fontsize keys
_fontsize_keys = ['xlabel','ylabel', 'zlabel', 'labels',
'xticks', 'yticks', 'zticks', 'ticks',
_fontsize_keys = ['xlabel','ylabel', 'zlabel', 'clabel', 'labels',
'xticks', 'yticks', 'zticks', 'cticks', 'ticks',
'minor_xticks', 'minor_yticks', 'minor_ticks',
'title', 'legend', 'legend_title',
]
Expand Down Expand Up @@ -484,9 +484,9 @@ def _fontsize(self, key, label='fontsize', common=True):

if key in self.fontsize:
return {label:self.fontsize[key]}
elif key in ['zlabel', 'ylabel', 'xlabel'] and 'labels' in self.fontsize:
elif key in ['zlabel', 'ylabel', 'xlabel', 'clabel'] and 'labels' in self.fontsize:
return {label:self.fontsize['labels']}
elif key in ['xticks', 'yticks', 'zticks'] and 'ticks' in self.fontsize:
elif key in ['xticks', 'yticks', 'zticks', 'cticks'] and 'ticks' in self.fontsize:
return {label:self.fontsize['ticks']}
elif key in ['minor_xticks', 'minor_yticks'] and 'minor_ticks' in self.fontsize:
return {label:self.fontsize['minor_ticks']}
Expand Down

0 comments on commit e0a1719

Please sign in to comment.