简体   繁体   English

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

[英]Bokeh and pandas- plotting empty graph reading data from csv

We are trying to plot a circle graph from a simple CSV file with two columns using Bokeh for data visualisation and Panda to read the CSV.我们正在尝试使用 Bokeh 进行数据可视化并使用 Panda 读取 CSV,从一个简单的 CSV 文件绘制一个圆图,该文件具有两列。 Following is our CSV file data where we are planning to plot graph Label X-axis and Average Y-axis.以下是我们计划绘制图表标签 X 轴和平均 Y 轴的 CSV 文件数据。 However its plotting empty graph.然而,它绘制的空图。

在此处输入图片说明

Following is our python script以下是我们的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)

I think you need to restructure your 'label' column as a number in order to achieve what you need with bokeh.我认为您需要将您的“标签”列重组为一个数字,以实现您对散景的需求。 I mean if you try exactly the same with a numerical variable instead of df['label'] it will be plotted.我的意思是,如果您尝试使用数字变量而不是 df['label'] 完全相同,它将被绘制。 In this case of course finally you need to relabel x axis with your desired values.在这种情况下,当然最后你需要用你想要的值重新标记 x 轴。 If you provide the csv file you will get more help.如果您提供 csv 文件,您将获得更多帮助。 But i think something equivalent to this must be done....但我认为必须做一些与此相当的事情......

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

and then plot using df['labels_tran'] as x axis然后使用 df['labels_tran'] 作为 x 轴绘制

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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