【发布时间】:2019-11-24 02:59:58
【问题描述】:
从 bokeh 的文档中,到目前为止我发现的 Timeseries 的唯一示例如下:Stock Returns
我找不到任何示例如何使用不同的绘图样式绘制时间序列。
有没有办法使用rect 函数创建一个时间序列图?更具体地说,以 x 刻度为单位的时间值。
【问题讨论】:
标签: python time-series bokeh
从 bokeh 的文档中,到目前为止我发现的 Timeseries 的唯一示例如下:Stock Returns
我找不到任何示例如何使用不同的绘图样式绘制时间序列。
有没有办法使用rect 函数创建一个时间序列图?更具体地说,以 x 刻度为单位的时间值。
【问题讨论】:
标签: python time-series bokeh
Timeseries 高级图表是折线图。对于其他用途,您需要使用bokeh.plotting API,它只是稍微冗长一些。除了rects 和quads, another option is to usesegmentand set theline_width` 要大。这可能对例如有用OHLC 类型图表。
【讨论】:
绘制rects 非常相似,但是您必须添加一些额外的参数来指定矩形的形状。
例如:
import numpy as np
import datetime
from bokeh.plotting import figure, show, output_notebook
dates = np.arange('2015-01-01', '2015-01-31', dtype='datetime64[D]')
values = np.cumprod(np.random.lognormal(0.0, 0.04, size=dates.size))
td = (dates[1]-dates[0]).item()
width = int(td.total_seconds() * 1000) # width in microseconds?
r = figure(x_axis_type="datetime")
r.rect(dates, values, height=40, width=width, angle=0,
height_units="screen", width_units="data")
show(r)
x 和y 指定rect 的中心,以及从该中心“移动”的宽度和高度。也可以考虑quads,区别见:
http://docs.bokeh.org/en/latest/docs/user_guide/plotting.html#bars-and-rectangles
结果:
【讨论】: