python - 如何在 Bokeh 中仅显示每第 n 个分类票

标签 python bokeh ticker

两年前有同样的问题。好像当时不支持every nth categorical tickers。

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

我的 Bokeh 版本是 0.12.13。我想知道现在是否支持它。

简单地设置 p.xaxis.ticker = ['A', 'B, 'C'] 不起作用(抛出错误)

在我的 dashbaord 中,初始绘图大小是浏览器视口(viewport)的四分之一,x 轴上挤满了许多股票代码和标签。所以我只想显示 10 个代码,然后在放大图时显示所有代码。

最佳答案

Bokeh 没有内置任何功能来执行此操作。你可以用 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()

请注意,上面定义的简单 get_ticks 不会处理具有嵌套类别等的更复杂情况。

关于python - 如何在 Bokeh 中仅显示每第 n 个分类票,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49172201/

相关文章:

python - 以编程方式运行 Bokeh 服务器以在本地浏览器中显示

python - Matplotlib pyplot 坐标轴格式化程序

javascript - jQuery 通过多个行情轮换

Python -> 函数 -> 如果没有为其中一个变量提供值

python : Solving a problem of finding a combination which satisfies a particular condition

javascript - 使用套索工具选择多线

postgresql - 建议的 Golang 架构,用于频繁轮询用户帐户

python - Facebook 使用 GET 而不是 POST 调用 Google App Engine 代码

python - 从 Python 中的文件数据错误导入

python - 如何在 Bokeh 中禁用滚轮缩放