How to add groupby attribute to scatter plot when plotting it as a new trace on top on gantt charts

Hi ,
I am trying to plot a line plot on top of gantt chart and need these lines to be grouped by a column from dataframe. However when adding a new trace on top of the gantt chart I am unable to add a group by something , which i can do when I just plot the lines using the px.line .

px.line(df_filtered, x=ā€œtimestamp_verboseā€, y=ā€œcumulative_distā€, color=ā€œgroupsā€,line_group=ā€œgroupsā€)
how do I write this same things as a scatter plot ?

This is my code for the plots ā€¦ I need the scatter_trace to replicate the px.line
import plotly.express as px
import plotly.graph_objs as go
from plotly.offline import iplot
fig = plt.figure(figsize=(20,10))
fig = ff.create_gantt(df_v3_gantt, colors=colors, index_col=ā€˜Resourceā€™, show_colorbar=False,
group_tasks=True,show_hover_fill=True,title=ā€˜TimeSpace Diagram only changes in v3_currStateā€™,
showgrid_x=True, showgrid_y=True,bar_width=0.5,height=700)
fig[ā€˜layoutā€™][ā€˜yaxisā€™].update(range=[-300,300])
fig.update_xaxes(rangeslider_visible=True)
scatter_trace=dict(type=ā€˜scatterā€™,
x= df_id2[ā€˜timestamp_verboseā€™],
y=df_id2[ā€˜distance_along_path_changeā€™] )

fig.add_trace(scatter_trace)
iplot(fig)

Thanks,
Shruti

1 Like

hi @empet ,

if you could help me with this it would be great thanks

Hi @snuchhi,

Welcome to plotly forum!!!
Unfortunately Iā€™m not working with plotly.express to help you.

To learn how px.line is defined print help(px.line).

When you managed to get
the fig1 =px.line(), then add to the fig returned by ff.create_gantt() all traces in fig1,
as follows:

for tr in fig1.data:
   fig.add_trace(tr)

HI @empet,
Hmm well let me try that, thank you. I was wondering if you knew how to do it with graph objects. Like when I add a trace scatter trace , is there a was to add a group by for the same ? I could not find anywhere to add some kind of grouping for the scatter plots.

Thanks,
Shruti