如何仅显示散景中的第n个类别行情自动收录器 [英] How to show only evey nth categorical tickers in Bokeh

查看:107
本文介绍了如何仅显示散景中的第n个类别行情自动收录器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

两年前有同样的问题.似乎当时不支持第n个分类报价器.

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

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

我的bokeh版本是0.12.13.我想知道现在是否支持它.

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

仅设置p.xaxis.ticker = ['A','B,'C']不起作用(引发错误)

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

在我的dashbaord中,初始绘图大小是浏览器视图端口的四分之一,并且x轴上挤满了许多行情指示器和标签.因此,我只想显示10个股票,然后在情节放大时显示所有股票.

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.

推荐答案

Bokeh并没有内置此功能.您可以使用自定义扩展

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()

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

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

这篇关于如何仅显示散景中的第n个类别行情自动收录器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆