I wonder if there is a neat way to implement a dumbbell plot in python with Plotly. I found that it is possible to construct it line by line by adding shapes (either manually like this, or calculating the values from data). For example:
data = pd.DataFrame(
{'Age': {
1: '16-24',
4: '16-24',
10: '25-34',
13: '25-34'
},
'Gender': {
1: 'Men',
4: 'Women',
10: 'Men',
13: 'Women'
},
'Medium+High': {
1: 9.100000000000001,
4: 26.0,
10: 15.2,
13: 19.1
}
})
fig = px.scatter(data, y="Age", x="Medium+High", color="Gender")
fig.update_layout(shapes=[
dict(
type= 'line',
yref= 'paper', y0= .94, y1= .94,
xref= 'x', x0= 10, x1= 5.3
)
])
That would produce the following plot (that would eventually become a dumbbell)
In R there is a very neat way to add the horizontal lines from the data (similar to how you would add traces). Is there an equivalent way to do this in python?