简体   繁体   中英

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.

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.

width=3600000 (3.6 million) gives bar widths of 1 hour, for example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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