Reputation: 701
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)
Upvotes: 3
Views: 3657
Reputation: 216
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.
Upvotes: 20