如何从python端为bokeh绘图指定第n个ticker,其中n是ticker的数量

如何从python端为bokeh绘图指定第n个ticker,其中n是ticker的数量,python,plot,bokeh,ticker,Python,Plot,Bokeh,Ticker,维护人员注意:对Coffeescript的支持已被弃用,并将在Bokeh 2.0中删除 前几天,我问起如何控制股票行情: 现在我需要从Coffeescript外部提供n,其中n是每n个股票代码 基于bigreddot提供的代码片段,并参考以下链接所示的代码示例: 虽然我不了解Coffescript,但我还是得到了以下非常简单的代码。但事实上,它并不起作用 编辑: 1) 下面是您可以复制并运行的完整代码。 2) 博克版本:0.12.13 Python:3.6.5 from bokeh.c

维护人员注意:对Coffeescript的支持已被弃用,并将在Bokeh 2.0中删除



前几天,我问起如何控制股票行情:

现在我需要从Coffeescript外部提供n,其中n是每n个股票代码

基于bigreddot提供的代码片段,并参考以下链接所示的代码示例:

虽然我不了解Coffescript,但我还是得到了以下非常简单的代码。但事实上,它并不起作用

编辑:

1) 下面是您可以复制并运行的完整代码。 2) 博克版本:0.12.13 Python:3.6.5

from bokeh.core.properties import Float, Instance, Tuple, Bool, Enum, String,Int
from bokeh.models import  TickFormatter, CategoricalTicker
from bokeh.io import show, output_file
from bokeh.plotting import figure

class MyTicker(CategoricalTicker):
    __implementation__ = """
    import {CategoricalTicker} from "models/tickers/categorical_ticker"
    import * as p from "core/properties"

    export class MyTicker extends CategoricalTicker
      type: "MyTicker"

      @define {
        nth: [ p.Int ]
      } 

      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 % this.nth == 0)

        return ticks

    """

    nth = Int(default=2)


output_file("bars.html")

fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']

p = figure(x_range=fruits, plot_height=250, title="Fruit Counts",
           toolbar_location=None, tools="")

p.vbar(x=fruits, top=[5, 3, 4, 2, 4, 6], width=0.9)

p.xgrid.grid_line_color = None
p.y_range.start = 0

p.xaxis.ticker = MyTicker(nth=2)

show(p)

“this.nth”似乎不起作用。结果是空的。

除非我弄错了,否则您只需要将
nth
作为一个实例变量来访问,方法是将
这个。
放在它前面

编辑:您还需要在过滤器中使用“胖箭头”
=>
,以便
正确绑定(否则
在该上下文中未定义)


感谢布莱恩的更新。然而不幸的是,“this.nth”不起作用。我刚刚放了一个完整的代码片段,要立即复制并运行。Bryan,谢谢你花时间回答我的问题。现在我最好自己花点时间学习咖啡脚本!:)
ticks.major = ticks.major.filter((element, index) => index % this.nth == 0)