Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for supplying fixed ticks with labels #1503

Merged
merged 1 commit into from May 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion holoviews/plotting/bokeh/element.py
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
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