pjford
December 11, 2018, 1:39am
1
I have these results using jupyter notebook / pandas / plotly ā
These refer to start and end times of a person working on days throughout the month of July.
Instead of two points on each end, what Iād really like are barsā¦ ideally something like this (which I made on adobe illustrator)ā¦ any help?
My code looks like this:
trace_start = go.Scatter(
x=df.date,
y=df[āstimeā],
mode=āmarkersā,
name = āstart timeā,
line = dict(color = āgreenā),
opacity = 0.8)
trace_end = go.Scatter(
x=df.date,
y=df[āetimeā],
mode=āmarkersā,
name = āend timeā,
line = dict(color = āredā),
opacity = 0.8)
data = [trace_start,trace_end]
layout = dict(
title = āTime Workedā,
xaxis = dict(
range = [ā2018-07-01ā,ā2018-07-31ā])
)
fig = dict(data=data, layout=layout)
py.iplot(fig, filename = āTime Workedā)
1 Like
jmmease
December 11, 2018, 11:10am
2
Hi @pjford ,
You can use the base
property of the bar
trace to control the starting height of bars in a bar chart. For example:
import pandas as pd
import plotly.graph_objs as go
fig = go.FigureWidget()
dates = pd.date_range('2018-01', '2018-12', freq='MS')
fig.add_bar(x=dates,
y=[2, 3, 4, 1, 4, 5, 3, 4, 5, 3, 2, 3],
base=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
fig
Note that in this case y
is not the top edge of the bar, but the height above the barās base
Hope that helps!
-Jon
1 Like
pjford
December 11, 2018, 8:03pm
3
This in theory seems like it would be a good solution, but when I run the sample code youāve provided it runs forever and I have to restart jupyter notebook because it never finishesā¦ any thoughts on whatās happening?
jmmease
December 12, 2018, 10:28am
4
Hmm, no I donāt have any ideas.
Maybe something is going wrong for you with FigureWidget
. Try displaying with iplot
like you were originally:
import pandas as pd
import plotly.graph_objs as go
from plotly.offline import init_notebook_mode, iplot
init_notebook_mode()
fig = go.Figure()
dates = pd.date_range('2018-01', '2018-12', freq='MS')
fig.add_bar(x=dates,
y=[2, 3, 4, 1, 4, 5, 3, 4, 5, 3, 2, 3],
base=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
iplot(fig)
pjford
December 12, 2018, 9:39pm
5
Thank you so much! I was able to get your example running. I changed the format a bit to make it about timeā¦ and came up with this below.
Iām still doing something wrong as there are these problems:
The duration/bar-length is incorrect
The X-axis is not showing the Jul-4 entry
The Y-axis appears to be out of orderā¦ 8am, 730am, 815amā¦
The Y-axis does not go far enough up
import pandas as pd
import plotly.graph_objs as go
from plotly.offline import init_notebook_mode, iplot
init_notebook_mode()
fig = go.Figure()
btime = pd.to_datetime(['2018-07-02 08:00','2018-07-03 07:30','2018-07-04 08:15'])
timedur = [pd.Timedelta('8 hours'),pd.Timedelta('8.25 hours'),pd.Timedelta('7.75 hours')]
thedates = pd.date_range('2017-07', '2017-08', freq='D')
fig.add_bar(x=thedates,
y=timedur,
base=btime)
iplot(fig)
Breakdown
Start time
End time
8:54 AM
9:05 AM
9:05 AM
8:55 AM
9:09 AM
9:16 AM
9:00 AM
9:07 AM
9:11 AM
9:03 AM
9:09 AM
9:14 AM
9:06 AM
9:22 AM
9:23 AM
9:07 AM
9:22 AM
9:22 AM
9:09 AM
9:12 AM
9:20 AM
9:10 AM
9:15 AM
9:21 AM
9:11 AM
9:22 AM
9:34 AM
9:15 AM
9:17 AM
9:18 AM
9:16 AM
9:37 AM
9:40 AM
9:16 AM
9:23 AM
9:31 AM
9:17 AM
9:33 AM
9:34 AM
9:19 AM
9:22 AM
9:31 AM
I have source file like this, how to generate chart that you shown, please help me get in ms excel or anything else
Thanks for the information. I will try to figure it out for more.
www.myaarpmedicare.com