最近我开始用bokeh库进行数据可视化。我的任务是通过python将CSV数据转换成图形。我面临一些问题。下面是我的环境结构和问题。在
我需要从名为“的CSV文件中获取数据”数据.csv". 我的文件结构如下: Id,上字节,下字节,时间“时间戳”。我需要帮助来获取数据图.多线. 我抓住了我的机会,但数据还是没有如我所愿。在
我的代码:
def run_graph():
df = pandas.read_csv("/Users/path/fetch_data.csv",parse_dates["StatTime"])
p = Figure(width=500, height=250, x_axis_type="datetime", responsive=True,
tools="pan, box_zoom, wheel_zoom, save, reset",logo =None,
title="Graph:", x_axis_label="Time Frame", y_axis_label="Traffic")
timeFrame = df["Time"]
upbyte = df["up"]
downbyte = df["Down"]
protocolname = df["Name"]
p.multi_line(x = [timeFrame, upbyte], y = [timeFrame, downbyte], color=['Red', 'green'], line_width=1)
p.circle(x = [timeFrame, upbyte], y = [timeFrame, downbyte], fill_color='orange', size=6)
output_file("/Users/path/graph.html", title="Reports")
show(p)
run_graph()
脚本错误是: 错误:类型错误给定参数(1:3)
我希望我的问题对每个人都很清楚。如果没有请让我知道,以提供更多的细节。先谢谢你
我想你应该用x轴作为时间戳来绘制上行字节和下行字节。我看到您的数据对于每个时间戳都有多个记录。我只添加了几行,使图形更易于理解-
要使图形正确,请使用代码-
多行需要不同系列的所有x和不同系列的所有y作为列表列表。所以你的Xs只是时间戳的重复。在
此外,还需要使用圆高亮显示点。为此,您需要使用circle方法两次,因为它不提供任何类似multi_circle的选项。在
现在,我想您应该首先在时间戳级别汇总数据,然后绘制。如果绘制汇总数据,它将如下所示-
相关问题 更多 >
编程相关推荐