Reputation: 107
Recently I start working on data visualization with bokeh library. my task is to take a CSV data an turn it to graph via python. i'm facing some issues here. below is my environment structure and problem.
I need to take a data from CSV file named by "data.csv". my file structure is look like: Id, upbyte, downbyte,time "timestamp". I need assistance to drow the data with figure.multi_line. i toke my chance but still the data not coming like i wanted.
My_Code:
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()
The script error is: Error:TypeError: multiline() takes exactly 3 arguments (1 given)
i hope my question was clear for everyone. If not please let me know to provide you with more details. Thank you in advance Gent's.
Upvotes: 0
Views: 283
Reputation: 2103
I think you want to plot the upbytes and downbytes both with x-axis as time stamp. I see that your data has multiple records for each timestamp. I just added a few more rows to make graph a bit more understandable -
To get the graph correct, use the code -
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 requires all the xs of different series and and all ys of different series as list of lists. So your Xs are just the repeat of timestamps.
Also, you want to highlight the points using circles. For that you need to use circle method twice, as it doesn't provide any such option as multi_circle.
Now, I guess you want to first summarize your data at timestamp level and then plot. If you plot summarized data, it will look like this -
Upvotes: 2