如何将X轴设置为散景图上的日期时间? [英] How can I set the x-axis as datetimes on a bokeh plot?

查看:493
本文介绍了如何将X轴设置为散景图上的日期时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将bokeh与ipython笔记本一起使用.

I'm using bokeh with an ipython notebook.

我想使用包含日期时间的pandas DataFrame在bokeh中绘制折线图:

I want to plot a line graph in bokeh using a pandas DataFrame containing datetimes:

import pandas as pd
from datetime import datetime as dt
from bokeh.io import output_notebook
from bokeh.charts import Bar, Line, show

df = pd.DataFrame(data=[1,2,3],
                  index=[dt(2015, 1, 1), dt(2015, 1, 2), dt(2015, 1, 3)],
                  columns=['foo'])

output_notebook()
show(Line(df))

但是,散景使用微秒!为什么是这样?我该如何解决?

However, bokeh uses microseconds! Why is this? How do I fix it?

推荐答案

从bokeh 0.12.3开始,您现在可以执行以下操作:

As of bokeh 0.12.3, you can now do:

p = figure(..., x_axis_type='datetime', ...)

这篇关于如何将X轴设置为散景图上的日期时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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