Skip to content

Commit

Permalink
Added support for supplying fixed ticks with labels
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed May 31, 2017
1 parent 12b0815 commit beec59d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
8 changes: 7 additions & 1 deletion holoviews/plotting/bokeh/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,13 @@ def _axis_properties(self, axis, key, plot, dimension=None,
axis_props['ticker'] = BasicTicker(desired_num_ticks=ticker)
elif isinstance(ticker, (tuple, list)):
if all(isinstance(t, tuple) for t in ticker):
pass
ticks, labels = zip(*ticker)
axis_props['ticker'] = FixedTicker(ticks=ticks)
if bokeh_version > '0.12.5':
axis_props['major_label_overrides'] = dict(ticker)
else:
self.warning('Explicit tick labels not supported until'
'bokeh 0.12.6, please upgrade')
else:
axis_props['ticker'] = FixedTicker(ticks=ticker)

Expand Down
18 changes: 18 additions & 0 deletions tests/testplotinstantiation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1401,12 +1401,30 @@ def test_element_xticks_list(self):
self.assertIsInstance(plot.xaxis[0].ticker, FixedTicker)
self.assertEqual(plot.xaxis[0].ticker.ticks, [0, 5, 10])

def test_element_xticks_list_of_tuples(self):
if bokeh_version < str('0.12.6'):
raise SkipTest('Bokeh 0.12.6 required for specifying explicit tick labels')
ticks = [(0, 'zero'), (5, 'five'), (10, 'ten')]
curve = Curve(range(10))(plot=dict(xticks=ticks))
plot = bokeh_renderer.get_plot(curve).state
self.assertIsInstance(plot.xaxis[0].ticker, FixedTicker)
self.assertEqual(plot.xaxis[0].major_label_overrides, dict(ticks))

def test_element_yticks_list(self):
curve = Curve(range(10))(plot=dict(yticks=[0, 5, 10]))
plot = bokeh_renderer.get_plot(curve).state
self.assertIsInstance(plot.yaxis[0].ticker, FixedTicker)
self.assertEqual(plot.yaxis[0].ticker.ticks, [0, 5, 10])

def test_element_xticks_list_of_tuples(self):
if bokeh_version < str('0.12.6'):
raise SkipTest('Bokeh 0.12.6 required for specifying explicit tick labels')
ticks = [(0, 'zero'), (5, 'five'), (10, 'ten')]
curve = Curve(range(10))(plot=dict(yticks=ticks))
plot = bokeh_renderer.get_plot(curve).state
self.assertIsInstance(plot.yaxis[0].ticker, FixedTicker)
self.assertEqual(plot.yaxis[0].major_label_overrides, dict(ticks))

def test_overlay_xticks_list(self):
overlay = (Curve(range(10)) * Curve(range(10)))(plot=dict(xticks=[0, 5, 10]))
plot = bokeh_renderer.get_plot(overlay).state
Expand Down

0 comments on commit beec59d

Please sign in to comment.