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

Bokeh和pandas-绘制从csv读取数据的空图形

  •  0
  • Saagar  · 技术社区  · 6 年前

    我们试图从一个简单的CSV文件中绘制一个圆图,其中包含两列,使用Bokeh进行数据可视化,Panda读取CSV。下面是我们的CSV文件数据,我们计划在其中绘制图形标签X轴和平均Y轴。然而,它绘制的是空图。

    enter image description here

    下面是我们的python脚本

    from bokeh.plotting import figure, output_file, show
    import pandas as pd
    from bokeh.models import DatetimeTickFormatter, ColumnDataSource
    from bokeh.models.tools import HoverTool
    
    output_file('columndatasource_example.html')
    df = pd.read_csv(r"E:/MySpace/pythonTest/aggregate3.csv")
    sample= df.sample(5)
    source = ColumnDataSource(sample)
    #print(df.columns.tolist())
    p = figure()
    p.circle(x='Label', y='Average',
         source=source,
         size=5, color='green')
    p.title.text = 'BPM Load test results'
    p.xaxis.axis_label = 'Request name'
    p.yaxis.axis_label = 'Response time in miliseconds'
    hover = HoverTool()
    hover.tooltips=[
    ('Request Name', '@Label'),
    ('Response Time', '@Average'),
    ('Throughput', '@Throughput')    
    ]
    p.add_tools(hover)
    show(p)
    
    0 回复  |  直到 6 年前
        1
  •  0
  •   Ignatios Chatzidiamantis    6 年前

    我认为你需要把你的“标签”栏重新组织成一个数字,这样才能达到你对博凯的要求。我的意思是如果你用一个数值变量而不是df['label']来尝试同样的方法,它就会被绘制出来。当然,在这种情况下,最后需要用所需的值重新标记x轴。如果您提供csv文件,您将获得更多帮助。但我认为必须采取类似的措施。。。。

    labels0 = df['Label'].tolist()
    un_labels = list(sorted(set(df['Label'])))
    labels_tran = []
    for label in labels0:
        labels_tran.append(un_labels.index(label))
    df['labels_tran'] = labels_tran
    

    然后用df['labels_tran']作为x轴绘图