gpt4 book ai didi

python - 带有 Bokeh vbar 图的分类 y 轴和日期时间 x 轴

转载 作者:行者123 更新时间:2023-11-28 20:02:36 24 4
gpt4 key购买 nike

我想使用 Bokeh 绘制一个 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)

它看起来不错,只是它不是条形。

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

最佳答案

我自己刚遇到这个问题。对于日期时间 x 轴,vbar 宽度需要很大,因为日期时间轴必须具有毫秒分辨率。

例如,

width=3600000(360 万)条宽度为 1 小时。

关于python - 带有 Bokeh vbar 图的分类 y 轴和日期时间 x 轴,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45711567/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com