✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🧬 Learn how to build RNA-Seq data apps with Python & Dash. Register for the May 20 Webinar!

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