带有bokeh vbar图的分类y轴和日期时间x轴 [英] categorical y-axis and datetime x-axis with Bokeh vbar plot

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

问题描述

我想使用bokeh绘制vbar图,其中x轴为日期时间,y轴为分类值.

I want to draw a vbar plot using bokeh, where x-axis takes datetime and y-axis takes categorical values.

最初,我尝试如下绘制圆形图:

Initially I tried circle plot as follows:

import pandas as pd
from datetime import datetime
from dateutil.parser import parse    
from bokeh.plotting import figure, show, output_notebook    
from bokeh.models.ranges import FactorRange

x = pd.Series(['2017/1/1', '2017/1/2', '2017/1/3', '2017/1/4']).map(lambda x: parse(x))
y = ["a", "b", "c", "a"]

p = figure(x_axis_type='datetime', y_range=list(set(y)), plot_width=400, plot_height=200)
p.circle(x, y, size=10, line_color="blue", line_width=1)
show(p)

看起来不错,除了它不是条形.

It looks good except for the fact that it is not in bar form.

接下来,我尝试了以下代码,但未显示图:

Next, I tried the following code but no plots are displayed:

x = pd.Series(['2017/1/1', '2017/1/2', '2017/1/3', '2017/1/4']).map(lambda x: parse(x))
y = ["a", "b", "c", "a"]

p = figure(x_axis_type='datetime', y_range=list(set(y)), plot_width=400, plot_height=200)
p.vbar(x=x, bottom=0, top=y, width=0.1, color="blue")

show(p)

推荐答案

我自己也遇到了这个问题.对于日期时间x轴,由于日期时间轴必须具有毫秒级的分辨率,因此vbar宽度必须很大.

Just ran into this problem myself. With a datetime x-axis, the vbar width needs to be huge since the datetime axis must have a resolution of milliseconds.

width = 3600000(360万)给出的条形宽度为1小时.

width=3600000 (3.6 million) gives bar widths of 1 hour, for example.

这篇关于带有bokeh vbar图的分类y轴和日期时间x轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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