Broken barh plot

Hello, I would like to create a broken barh plot using Plotly for Python, do you have any suggestion/boilerplate code that I could start from?
I am talking about something like this: https://matplotlib.org/3.1.1/gallery/lines_bars_and_markers/broken_barh.html

Hi @robertopreste,

Broken bars can be defined as Plotly shapes https://plot.ly/python/shapes/:

import plotly.graph_objs as go

def broken_bars(xstart, xwidth, ystart, yh, colors):
    #xstart - list of x-start coord for each bar
    #xwidth = list of bar widths
    #ystart - number y-start coord for each bar
    #yh - number- height of eah bar
    #colors = list of bar colors
    
    if len(xstart) != len(xwidth) or  len(xstart) != len(colors):
        raise ValueError('xstart, xwidth and colors must have the same length')
    shapes = []    
    for k in range(len(xstart)):
        shapes.append(dict(type="rect",
                           x0=xstart[k],
                           y0=ystart,
                           x1=xstart[k] + xwidth[k],
                           y1=ystart+yh,
                           fillcolor=colors[k],
                           line_color=colors[k]))
    return shapes    


fig = go.Figure()
fig.update_layout(width=600, height=500,
                  xaxis_range = [0, 150],
                  yaxis_range = [0, 40],
                  shapes=broken_bars([10, 100, 130 ], [50, 20, 10], 20, 9, 
                                     colors=['orange', 'green', 'red' ]))

broken_bars

With this definition no info is displayed on hover. But you can define the bars as a list of Scatter filled plots (see the first examples at the link above):

def broken_bars2(xstart, xwidth, ystart, yh, colors):
    #the same tests as above
    data =[]
    for k in range(len(xstart)):
        data.append(go.Scatter(x = [xstart[k], xstart[k]+xwidth[k],xstart[k]+xwidth[k], xstart[k]],
                               y = [ystart]*2+[ystart+yh]*2, fill='toself', fillcolor=colors[k], mode='lines',
                               line_color=colors[k], name=f'bar{k}'))
                    
    return data
fig = go.Figure(data= broken_bars2([10, 100, 130 ], [50, 20, 10], 20, 9, 
                                     colors=['orange', 'green', 'red' ]))
fig.update_layout(width=600, height=500,
                  xaxis_range = [0, 150],
                  yaxis_range = [0, 40]);

Thanks @empet, this seems exactly what I was looking for! I will experiment a bit with it asap, thanks again for your suggestion!