2017-08-16 102 views
0

我想绘制一个虚拟散点图使用散景,其中x轴采取日期时间和y轴采取分类值。分类y轴和日期时间x轴与散景vbar阴谋

起初我想圆情节如下:

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) 

它看起来只是一个事实,即它不是在酒吧的形式很好。

enter image description here

接下来,我尝试下面的代码,但没有显示地块:

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) 

enter image description here

回答

2

恰好碰到了这个问题我自己。使用日期时间x轴时,由于日期时间轴必须具有毫秒分辨率,因此vbar宽度需要很大。例如,

width = 3600000(360万)给出1小时的条宽。

+0

啊哈,我明白了!非常感谢! – Royalblue