Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
482 views
in Technique[技术] by (71.8m points)

python - How to show only evey nth categorical tickers in Bokeh

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...