2017-08-16 108 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