2

There was the same question two years ago. It seemed that evey nth categorical tickers was not supported at that time.

https://stackoverflow.com/questions/34949298/python-bokeh-show-only-every-second-categorical-ticker

My bokeh version is 0.12.13. I wonder it is supported now.

Simply setting p.xaxis.ticker = ['A', 'B, 'C'] does not work(error is thrown)

In my dashbaord, the initial plot size is one quarter of browser view port and the x axis is crowded with many ticker and labels. So I want to show only 10 tickers and later show all of them when the plot is enlarged.

Royalblue
  • 639
  • 10
  • 22
  • Please don't edit answered questions to ask new questions, it is confusing for everyone involved. It is best to simply ask a new question. – bigreddot Apr 05 '18 at 03:21
  • @ bigreddot, that is right. I will ask a new one. :) – Royalblue Apr 05 '18 at 03:56
  • I asked a new question here: https://stackoverflow.com/questions/49663952/how-to-specify-n-th-ticker-for-bokeh-plot-from-python-side-where-n-is-the-numbe – Royalblue Apr 05 '18 at 04:06

1 Answers1

3

There's nothing built in to Bokeh to do this. You could accomplish something with a custom extension:

from bokeh.models CategoricalTicker

JS_CODE = """
import {CategoricalTicker} from "models/tickers/categorical_ticker"

export class MyTicker extends CategoricalTicker
  type: "MyTicker"

  get_ticks: (start, end, range, cross_loc) ->
    ticks = super(start, end, range, cross_loc)

    # drops every other tick -- update to suit your specific needs
    ticks.major = ticks.major.filter((element, index) -> index % 2 == 0)

    return ticks

"""

class MyTicker(CategoricalTicker):
    __implementation__ = JS_CODE

p.xaxis.ticker = MyTicker()

Note that the simple get_ticks defined above will not handle more complicated situations with nested categories, etc.

bigreddot
  • 33,642
  • 5
  • 69
  • 122
  • @bigreddot I have been trying to implement this solution, but within a tab in a bokeh server. When I include plot.axis.ticker = MyTicker() all of the tabs end up consolidated and partially loaded into one tab. Any idea why that might happen? have been banging my head against it for a day now. – StormsEdge Jul 31 '18 at 15:14
  • No idea at all, please open a new question with complete minimal code to reproduce. – bigreddot Jul 31 '18 at 22:17
  • Just tried this with Bokeh 3.0.3 and not luck. Various errors reported by the Bokeh Compiler, with not very helpful feedback either alas. Seems Bokeh attempts to compile the __implementation__ in `bokeh/util/compiler.py` – Bernd Wechner Dec 25 '22 at 03:04
  • Bokeh 3 was a new major revision, so breaking changes are to be expected. It's probably time we just find some built-in accommodation for this, though, since it is common enough. Please open a [GitHub dev discussion](https://github.com/bokeh/bokeh/discussions) and I will circle in more core devs. Please reference this SO question also https://stackoverflow.com/questions/49663952/how-to-specify-n-th-ticker-for-bokeh-plot-from-python-side-where-n-is-the-numbe – bigreddot Dec 28 '22 at 19:14
  • This does not work in Bokeh 3.0.3 indeed. I wonder what does? – Bernd Wechner Feb 10 '23 at 10:52
  • Not sure. I've expressed willingness to try and work through things on a GH discussion, where its easier to circle in other core devs, but so far no one has decided to create a discussion. – bigreddot Feb 10 '23 at 16:10