Python bokeh的Python数据可视化

2024-09-30 08:29:46 发布

您现在位置:Python中文网/ 问答频道 /正文

最近我开始用bokeh库进行数据可视化。我的任务是通过python将CSV数据转换成图形。我面临一些问题。下面是我的环境结构和问题。在

环境

  • python=2.7.14
  • 波基=0.12.13

问题描述

我需要从名为“的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)

我希望我的问题对每个人都很清楚。如果没有请让我知道,以提供更多的细节。先谢谢你


Tags: 文件csv数据df字节环境错误时间
1条回答
网友
1楼 · 发布于 2024-09-30 08:29:46

我想你应该用x轴作为时间戳来绘制上行字节和下行字节。我看到您的数据对于每个时间戳都有多个记录。我只添加了几行,使图形更易于理解-

enter image description here

要使图形正确,请使用代码-

p = figure(width=500, height=250, x_axis_type="datetime",  
    tools="pan, box_zoom, wheel_zoom, save, reset",logo =None, 
    title="OTT Traffic Utilization Graph:", x_axis_label="Time Frame", y_axis_label="Traffic Utilization")
p.multi_line(xs = [timeFrame, timeFrame], ys = [upbyte, downbyte], color=['Red', 'green'], line_width=1)
p.circle(x = timeFrame, y = upbyte, fill_color='red', size=6)
p.circle(x = timeFrame, y = downbyte, fill_color='green', size=6)
show(p)

enter image description here

多行需要不同系列的所有x和不同系列的所有y作为列表列表。所以你的Xs只是时间戳的重复。在

此外,还需要使用圆高亮显示点。为此,您需要使用circle方法两次,因为它不提供任何类似multi_circle的选项。在

现在,我想您应该首先在时间戳级别汇总数据,然后绘制。如果绘制汇总数据,它将如下所示- enter image description here

相关问题 更多 >

    热门问题