Skip to content

Commit

Permalink
Fix categorical labels
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuang11 committed Oct 5, 2018
1 parent 7d1f7a6 commit 92eb963
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion holoviews/plotting/bokeh/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,23 @@
import numpy as np
import bokeh
import bokeh.plotting
from holoviews.plotting.bokeh.util import bokeh_version
from bokeh.core.properties import value
from bokeh.models import (HoverTool, Renderer, Range1d, DataRange1d, Title,
FactorRange, FuncTickFormatter, Tool, Legend)
from bokeh.models.tickers import Ticker, BasicTicker, FixedTicker, LogTicker
from bokeh.models.widgets import Panel, Tabs
from bokeh.models.mappers import LinearColorMapper
from bokeh.models import CategoricalAxis
try:
from bokeh.models import ColorBar
from bokeh.models.mappers import LogColorMapper, CategoricalColorMapper
except ImportError:
LogColorMapper, ColorBar = None, None
if bokeh_version <= '0.13.0':
built_in_themes = {}
else:
from bokeh.themes import built_in_themes
from bokeh.plotting.helpers import _known_tools as known_tools

from ...core import DynamicMap, CompositeOverlay, Element, Dimension
Expand Down Expand Up @@ -389,7 +395,12 @@ def _axis_properties(self, axis, key, plot, dimension=None,
Returns a dictionary of axis properties depending
on the specified axis.
"""
axis_props = {}
try:
axis_props = (built_in_themes[self.renderer.theme]
._json['attrs'].get('Axis', {}))
except KeyError:
axis_props = {}

if ((axis == 'x' and self.xaxis in ['bottom-bare', 'top-bare']) or
(axis == 'y' and self.yaxis in ['left-bare', 'right-bare'])):
axis_props['axis_label_text_font_size'] = value('0pt')
Expand Down Expand Up @@ -434,6 +445,20 @@ def _axis_properties(self, axis, key, plot, dimension=None,
if jsfunc:
formatter = FuncTickFormatter(code=jsfunc)
axis_props['formatter'] = formatter

if axis == 'x':
xaxis = plot.xaxis[0]
if isinstance(xaxis, CategoricalAxis):
# can't just dump this with the rest of axis_props
# always complains about LinearAxis does not have
# 'group_...' attribute
group_label_props = {}
for key in list(axis_props):
if key.startswith('major_label'):
new_key = key.replace('major_label', 'group')
group_label_props[new_key] = axis_props[key]
xaxis.update(**group_label_props)

return axis_props


Expand Down Expand Up @@ -491,6 +516,7 @@ def _update_ranges(self, element, ranges):
xfactors, yfactors = None, None
if any(isinstance(ax_range, FactorRange) for ax_range in [x_range, y_range]):
xfactors, yfactors = self._get_factors(element)

framewise = self.framewise
streaming = (self.streaming and any(stream._triggering for stream in self.streaming))
xupdate = ((not self.model_changed(x_range) and (framewise or streaming))
Expand Down

0 comments on commit 92eb963

Please sign in to comment.