I'm trying to show difference between bars using annotation. Specifically, showing difference between all bars with respect to the first bar.
My code is shown below:
import plotly.graph_objects as go
lables = ['a','b','c']
values = [30,20,10]
difference = [ str(values[0] - x) for x in values[1:] ]
fig = go.Figure( data= go.Bar(x=lables,y=values,width = [0.5,0.5,0.5] ) )
fig.add_annotation( x=lables[0],y= values[0],
xref="x",yref="y",
showarrow=True,arrowhead=7,
ax = 1200, ay= 0 )
fig.add_annotation( x = lables[1], y=values[0],
xref="x",yref="y",
showarrow=True,arrowhead=1,
ax = 0 , ay = 100,
text= difference[0]
)
fig.show()
The result graph looks like:
As you can see, I'm trying to use annotation to indicate the difference between a
and b
. But I don't know how to get the vertical distance between the horizontal line from a
and the top of the b
.
I'm trying to have an arrow point to the top of b
and c
from the horizontal line. I'm wondering is there a way to get this vertical distance or are there any other ways to achieve the same result?