categorical y-axis and datetime x-axis with Bokeh vbar plot

十年热恋 提交于 2019-12-07 18:40:12

问题


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)


回答1:


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 (3.6 million) gives bar widths of 1 hour, for example.



来源:https://stackoverflow.com/questions/45711567/categorical-y-axis-and-datetime-x-axis-with-bokeh-vbar-plot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!