bokeh.charts.Area中的日期时间x轴 [英] Datetime x axis in bokeh.charts.Area

查看:83
本文介绍了bokeh.charts.Area中的日期时间x轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我以x轴为datetime系列来绘制数据,却将其解释为datetime值,但错误的是:我的2016年时间被解释为1970-1-1之后的毫秒数.代码:

Why I plot my data with a datetime series as x axis, it is interpreted as a datetime value, but the wrong one: my 2016 times are interpreted as milliseconds after 1970-1-1. Code:

from __future__ import absolute_import, division, print_function
from __future__ import unicode_literals

from datetime import datetime
import pandas as pd
from bokeh.charts import Area, show, output_file

df = pd.DataFrame()
df['date'] = [datetime(2016, 1, 1), datetime(2016, 1, 2), datetime(2016, 1, 3)]
df['v1'] = [1, 2, 3]
df['v2'] = [4, 4, 3]

p = Area(df, x='date', y=['v1', 'v2'], title="Area Chart",
         legend="top_left", xscale='datetime', stack=True,
         xlabel='time', ylabel='values')

output_file("area.html", title="Area Chart")
show(p)

有没有办法让bokeh.charts.Area识别我的datetime数据,还是我必须自己使用figure()构造图?

Is there a way I can get bokeh.charts.Area recognize my datetime data, or do I have to construct the plot myself using figure()?

其他数据:Python 2.7上的bokeh 0.11.1

Additional data: bokeh 0.11.1 on Python 2.7

推荐答案

问题出在from __future__ import unicode语句.*删除该行解决了该问题.

The problem was the from __future__ import unicode statement.* Removing the line fixed the problem.

核心问题是x='date'关键字参数必须为字节.否则,散景将无法在数据框中找到关键帧.在这种情况下,它不会显示警告或错误,它只是以数字索引(0、1、2、3)以无声方式替换,该数字索引由日期轴解释为毫秒.

The core issue is that the the x='date' keyword argument must be bytes. Otherwise bokeh will not find the key in the dataframe. It does not show a warning or error in this case, it just silently replaces it with a numerical index (0, 1, 2, 3), which is interpreted as milliseconds by the date axis.


*排除在最初的问题之外,因为在与剩余的.egg-info目录有些混淆之后,同样的问题也浮出水面.


* Left out of the original question, because the same problem also surfaced after some pip confusion with leftover .egg-info directories.

这篇关于bokeh.charts.Area中的日期时间x轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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