简体   繁体   English

分类y轴和日期时间x轴与Bokeh vbar图

[英]categorical y-axis and datetime x-axis with Bokeh vbar plot

I want to draw a vbar plot using bokeh, where x-axis takes datetime and y-axis takes categorical values. 我想使用散景绘制vbar图,其中x轴采用日期时间,y轴采用分类值。

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)

在此输入图像描述

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. 对于日期时间x轴,vbar宽度需要很大,因为日期时间轴必须具有毫秒的分辨率。

width=3600000 (3.6 million) gives bar widths of 1 hour, for example. 例如,width = 3600000(360万)给出1小时的条宽。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM