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

Python Bokeh和pandas-绘制从csv读取数据的空图形,python,pandas,bokeh,pandas-bokeh,Python,Pandas,Bokeh,Pandas Bokeh,我们正在尝试从一个简单的CSV文件中绘制一个圆图,该文件有两列,使用Bokeh进行数据可视化,使用Panda读取CSV。下面是我们的CSV文件数据,我们计划在其中绘制图形标签X轴和平均Y轴。然而,它绘制的是空图 下面是我们的python脚本 from bokeh.plotting import figure, output_file, show import pandas as pd from bokeh.models import DatetimeTickFormatter, ColumnD

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

下面是我们的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)

我认为您需要将“标签”列重组为一个数字,以实现您对bokeh的需求。我的意思是,如果你尝试完全相同的数值变量,而不是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轴进行绘图