代码之家  ›  专栏  ›  技术社区  ›  Royalblue

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

  •  2
  • Royalblue  · 技术社区  · 8 年前

    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

    1 回复  |  直到 7 年前
        1
  •  16
  •   Matt Thompson    8 年前

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