From beec59d01133a5d15c1542ebc5889c00612b0918 Mon Sep 17 00:00:00 2001
From: Philipp Rudiger
Date: Wed, 31 May 2017 18:29:44 +0100
Subject: [PATCH] Added support for supplying fixed ticks with labels
---
holoviews/plotting/bokeh/element.py | 8 +++++++-
tests/testplotinstantiation.py | 18 ++++++++++++++++++
2 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/holoviews/plotting/bokeh/element.py b/holoviews/plotting/bokeh/element.py
index cadecb84d2..d33d31b0d1 100644
--- a/holoviews/plotting/bokeh/element.py
+++ b/holoviews/plotting/bokeh/element.py
@@ -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)
diff --git a/tests/testplotinstantiation.py b/tests/testplotinstantiation.py
index 596ff85eb6..fed4f15a3e 100644
--- a/tests/testplotinstantiation.py
+++ b/tests/testplotinstantiation.py
@@ -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