带有散景 vbar 图的分类 y 轴和日期时间 x 轴
categorical y-axis and datetime x-axis with Bokeh vbar plot
我想使用散景绘制一个 vbar 图,其中 x 轴采用日期时间,y 轴采用分类值。
最初我尝试了圆图如下:
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)
除了不是条形,看起来还不错
接下来,我尝试了以下代码,但没有显示任何图:
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)
我自己就 运行 解决了这个问题。对于日期时间 x 轴,vbar 宽度需要很大,因为日期时间轴必须具有毫秒分辨率。
例如,width=3600000(360 万)条宽度为 1 小时。
我想使用散景绘制一个 vbar 图,其中 x 轴采用日期时间,y 轴采用分类值。
最初我尝试了圆图如下:
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)
除了不是条形,看起来还不错
接下来,我尝试了以下代码,但没有显示任何图:
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)
我自己就 运行 解决了这个问题。对于日期时间 x 轴,vbar 宽度需要很大,因为日期时间轴必须具有毫秒分辨率。
例如,width=3600000(360 万)条宽度为 1 小时。