Z index of each trace

I plot Gantt chart and scatter in the same layout but the scatter and its text are underneath the Gantt chart.

is it possible to bring the scatter on top of the Gantt so the scatter ate its text are visible?

here is my chart
https://plot.ly/~cameron54/36

Hi @cameron54,

Correct me if I’m wrong, but it looks like you used the figure_factory.create_gantt function to build the original figure, and then added a scatter trace afterward.

The issue you’re running into is that the bars in the Gantt chart aren’t traces like the scatter trace, they are shapes (See https://plot.ly/python/shapes/), so they don’t follow the same layering rules as traces. That’s why the scatter trace you appended to the end doesn’t end up on top.

Fortunately, shapes have their own layer property (See https://plot.ly/python/reference/#layout-shapes-layer) that you can be set to 'above' (the default) or 'below' (what I think you want).

The figure factor function doesn’t have an option to change the layer, but you can do so after the figure is constructed like this

for bar in fig['layout']['shapes']:
    bar['layer'] = 'below'

Also, in case it’s helpful for lining up your own scatter trace, you can also get the coordinates of each rectangle by looping over the shapes. e.g.

x0s = [bar['x0'] for bar in fig['layout']['shapes']]
x1s = [bar['x1'] for bar in fig['layout']['shapes']]
y0s = [bar['y0'] for bar in fig['layout']['shapes']]
y1s = [bar['y1'] for bar in fig['layout']['shapes']]

Hope that helps!
-Jon