I am trying to plot a timeline chart but they are stacking over each other.
import pandas as pd
import plotly.express as pex
d1 = dict(Start= '2021-10-10 02:00:00', Finish = '2021-10-10 09:00:00', Task = 'Sleep')
d2 = dict(Start= '2021-10-10 09:00:00', Finish = '2021-10-10 09:30:00', Task = 'EAT')
d3 = dict(Start= '2021-10-10 09:30:00', Finish = '2021-10-10 12:00:00', Task = 'Study')
d4 = dict(Start= '2021-10-10 12:00:00', Finish = '2021-10-10 16:00:00', Task = 'Work')
d5 = dict(Start= '2021-10-10 16:00:00', Finish = '2021-10-10 16:50:00', Task = 'EAT')
d6 = dict(Start= '2021-10-10 17:00:00', Finish = '2021-10-10 20:00:00', Task = 'Study')
d8 = dict(Start= '2021-10-10 20:00:00', Finish = '2021-10-10 20:40:00', Task = 'EAT')
d7 = dict(Start= '2021-10-10 21:00:00', Finish = '2021-10-11 05:00:00', Task = 'Sleep')
df = pd.DataFrame([d1,d2,d3,d4,d5,d6,d7,d8])
My DataFrame(df) is:
gantt = pex.timeline(df, x_start='Start', x_end = 'Finish', color = 'Task', height=300)
gantt.show()
This is the graph I am getting. But I don't want them to stack. I want them to be in a single line (There will not be any overlapping intervals). How do I achieve this?
CodePudding user response:
Try this
import pandas as pd
import plotly.express as pex
d1 = dict(stack=1, start='2021-10-10 02:00:00', finish='2021-10-10 09:00:00', task='Sleep')
d2 = dict(stack=1, start='2021-10-10 09:00:00', finish='2021-10-10 09:30:00', task='EAT')
d3 = dict(stack=1, start='2021-10-10 09:30:00', finish='2021-10-10 12:00:00', task='Study')
d4 = dict(stack=1, start='2021-10-10 12:00:00', finish='2021-10-10 16:00:00', task='Work')
d5 = dict(stack=1, start='2021-10-10 16:00:00', finish='2021-10-10 16:50:00', task='EAT')
d6 = dict(stack=1, start='2021-10-10 17:00:00', finish='2021-10-10 20:00:00', task='Study')
d8 = dict(stack=1, start='2021-10-10 20:00:00', finish='2021-10-10 20:40:00', task='EAT')
d7 = dict(stack=1, start='2021-10-10 21:00:00', finish='2021-10-11 05:00:00', task='Sleep')
df = pd.DataFrame([d1,d2,d3,d4,d5,d6,d7,d8])
gantt = pex.timeline(df, x_start='start', x_end='finish', y='stack', color='task', height=300)
gantt
CodePudding user response:
According to the documentation, you can use the y
parameter and provide an array_like object of size equal to the number of rows in df
and all elements equal.
So, one way (using the empty string ''
results in the plot having no y-axis
range):
gantt = pex.timeline(df, x_start='Start', x_end = 'Finish', color = 'Task', height=300, y=['']*df.shape[0])