0

Good day! So I am working with this dictionary data set in python. Say the dictionary looks like this:

time_sheet = {"hours_dan":[10, 8, 8, 11], "hours_john":[9, 8, 11], "hours_alex":[10, 8]}

My goal is to generate a scatter plot and have their names on the y-axis, and their hours on the x-axis. It would give me three lines and their time points on each line corresponding to their hours.

Is this achievable in Plotly Express? If not, what should I use to plot? Thank you so much!

1 Answer 1

1

To create a graph, the data format must be converted. Convert from dictionary format to data frame format. Prepare an empty data frame and use a loop process to retrieve keys and values and merge them sequentially into a data frame. For graphs, symbol markers are added in addition to the basic form, and text positions are modified.

import pandas as pd

df = pd.DataFrame()
time_sheet = {"hours_dan":[10, 8, 8, 11], "hours_john":[9, 8, 11], "hours_alex":[10, 8]}
for k,v in time_sheet.items():
    #print(k,v)
    df = pd.concat([df, pd.DataFrame({'name':k[6:], 'hours':v})],axis=0)

import plotly.express as px

fig = px.line(df, x='hours', y='name', color='name', text='hours', symbol='name')
fig.update_traces(textposition="bottom right")
fig.show()

enter image description here

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

Comments

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.