【问题标题】:Python Data visualization with python bokeh使用 python bokeh 的 Python 数据可视化
【发布时间】:2018-04-23 17:28:21
【问题描述】:

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

环境

  • python = 2.7.14
  • 散景 = 0.12.13

问题描述

我需要从名为“data.csv”的 CSV 文件中获取数据。我的文件结构是这样的: Id,upbyte,downbyte,时间“时间戳”。我需要帮助来使用 figure.multi_line 删除数据。我抓住了机会,但数据仍然没有像我想要的那样。

我的代码:

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()

错误

脚本错误是: 错误:TypeError:multiline() 只需要 3 个参数(给定 1 个)

我希望每个人都清楚我的问题。如果没有,请让我知道为您提供更多详细信息。提前谢谢你。

【问题讨论】:

    标签: python python-2.7 data-visualization bokeh


    【解决方案1】:

    我想你想用 x 轴作为时间戳来绘制 upbytes 和 downbytes。我看到您的数据对于每个时间戳都有多条记录。我只是添加了几行以使图表更易于理解 -

    要获得正确的图表,请使用代码 -

    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)
    

    multi_line 需要不同系列的所有 xs 和不同系列的所有 ys 作为列表列表。所以你的 X 只是时间戳的重复。

    另外,您想使用圆圈突出显示点。为此,您需要使用 circle 方法两次,因为它不提供 multi_circle 之类的选项。

    现在,我猜您想先在时间戳级别汇总您的数据,然后再进行绘图。如果您绘制汇总数据,它将如下所示 -

    【讨论】:

    • 你是最好的@Aritesh 先生。非常感谢您在这里的帮助。它就像一个静修所。请您指导我如何转换或汇总我的数据?
    • 你可以使用 pandas.DataFrame.groupby
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-08
    • 2018-01-10
    • 1970-01-01
    • 2020-07-11
    • 1970-01-01
    相关资源
    最近更新 更多