您有两个选择:
您可以使用日期时间轴:
p = figure(plot_width=400, plot_height=400, x_axis_type='datetime')
并通过任一datetime
对象或unix(自纪元以来的秒数)时间戳值作为x值。
e.g. df['month'] = [datetime.date(1900, x, 1) for x in df['month']]
然后,DatetimeTickFormatter 内容将修改标签的格式(完整月份名称、数字月份等)。这些文档在这里:
http://docs.bokeh.org/en/latest/docs/reference/models/formatters.html#bokeh.models.formatters.DatetimeTickFormatter http://docs.bokeh.org/en/latest/docs/reference/models/formatters.html#bokeh.models.formatters.DatetimeTickFormatter
Second:
您可以使用类似的分类 xaxis
p = figure(x_range=['Jan', 'Feb', 'Mar', ...)
绘制与 x_range 相对应的 x 值,例如:
x = ['Jan', 'Feb', 'Mar', ...]
y = [100, 200, 150, ...]
p.line(x, y)
用户指南在这里介绍了分类轴:
http://docs.bokeh.org/en/latest/docs/user_guide/plotting.html#categorical-axes http://docs.bokeh.org/en/latest/docs/user_guide/plotting.html#categorical-axes
这是一个例子: