Bokeh FixedTicker with Custom Datetime/Timestamp values

前端 未结 1 1813
南方客
南方客 2021-01-14 04:47

Objective: I want to have tick marks on the x axis only on 2017/10/2 and 2017/10/5. One constraint is that my times are not guaranteed to be evenly separated, so converting

相关标签:
1条回答
  • 2021-01-14 05:20

    Converting pandas Timestamps to integers gives nanoseconds. So dividing by 10^6 to get milliseconds works for me:

    y = list(range(3))
    x = pd.to_datetime(['2017-10-01', '2017-10-09', '2017-10-10'])
    tick_vals = pd.to_datetime(['2017-10-02', '2017-10-05']).astype(int) / 
    10**6
    
    fig = figure(x_axis_type='datetime')
    fig.line(x, y)
    fig.xaxis.ticker = FixedTicker(ticks=list(tick_vals)) 
    show(fig)
    
    0 讨论(0)
提交回复
热议问题