I am attempting to create a graph from a csv file using pandas and plotly. I have got most of it working, but can’t seem to add a title to the right hand legend. Each time I add the color=‘something’ I get an error:
Traceback (most recent call last):
File "C:\Users\c678014\py-progs\graph.py", line 7, in <module>
fig = px.line(df, x = 'Date', y = ['Download', 'Upload' ], color = 'Throughput', title='ALB DWI Performance')
File "C:\Users\c678014\AppData\Local\Programs\Python\Python39\lib\site-packages\plotly\express\_chart_types.py", line 252, in line
return make_figure(args=locals(), constructor=go.Scatter)
File "C:\Users\c678014\AppData\Local\Programs\Python\Python39\lib\site-packages\plotly\express\_core.py", line 1861, in make_figure
args = build_dataframe(args, constructor)
File "C:\Users\c678014\AppData\Local\Programs\Python\Python39\lib\site-packages\plotly\express\_core.py", line 1377, in build_dataframe
df_output, wide_id_vars = process_args_into_dataframe(
File "C:\Users\c678014\AppData\Local\Programs\Python\Python39\lib\site-packages\plotly\express\_core.py", line 1183, in process_args_into_dataframe
raise ValueError(err_msg)
ValueError: Value of 'color' is not the name of a column in 'data_frame'. Expected one of ['index', 'Date', 'Download', 'Upload', 'Ping', 'Jitter'] but received: Throughput
Here is my code that does not work:
import pandas as pd
import plotly.express as px
header_list = [ "Date", "Download", "Upload", "Ping" , "Jitter" ]
df = pd.read_csv('20210121-dwi-haigs-https.csv', names=header_list).reset_index()
fig = px.line(df, x = 'Date', y = ['Download', 'Upload' ], color = 'Throughput', title='ALB DWI Performance')
fig.update_layout(
xaxis_title='Time',
yaxis_title='Mbps'
)
fig.show()
Here is the code that almost works:
import pandas as pd
import plotly.express as px
header_list = [ "Date", "Download", "Upload", "Ping" , "Jitter" ]
df = pd.read_csv('20210121-dwi-haigs-https.csv', names=header_list).reset_index()
fig = px.line(df, x = 'Date', y = ['Download', 'Upload' ], title='ALB DWI Performance')
fig.update_layout(
xaxis_title='Time',
yaxis_title='Mbps'
)
fig.show()
Any help would be most appreciated
Pat