0

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.

Environment

  • python = 2.7.14
  • bokeh = 0.12.13

problem Description

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

Error

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.

1 Answer 1

2

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 -

enter image description here

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)

enter image description here

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 - enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

You are the best Mr. @Aritesh. Thank you very much for your assistance here. it works like an ashram. kindly can you guide me how to convert or summarize my data?
You can use pandas.DataFrame.groupby

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.