How to save labels on plotly box plot instead of it disappearing when not hovering on it

Hey guys, I would like the labels min, q1,q3 mean, max etc to appear on my box plot labels when not hovering on the graph. How would I be able to do this?
This is my code:

fig = go.Figure(data=[go.Box(y=1/(np.array(slopeP)),
            boxpoints='all', # can also be outliers, or suspectedoutliers, or False
            jitter=0.3, # add some jitter for a better separation between points
            pointpos=-1.8 # relative position of points wrt box
              )])
fig.update_layout(
    title="Boxplot of parameters A",
    xaxis_title="A",
    yaxis_title="A Parameters")

fig.show()

and I would like it to look like the data in this image to stay on the graph without hovering on it.

Any tips would be helpful.
Changing the trace 0 name would also be great.

Hi @QTPi,
A workaround for this would be to use annotations on your plot. You can use the values from the quartiles to determine the y value coordinate to position each label.

And to change β€˜trace 0’ label you can use the name parameter inside the go.Box() function.

Something like this:

fig = go.Figure(data=[go.Box(y=1/(np.array([1, 2, 3, 4, 5])),
            boxpoints='all', # can also be outliers, or suspectedoutliers, or False
            jitter=0.3, # add some jitter for a better separation between points
            pointpos=-1.8, # relative position of points wrt box
            name='Custom Name'  #add trace name(default = trace 0)
              )])
fig.add_annotation(x=0.3, y=1, #Max
            text="Max: 1",
            font=dict(size=16),
            showarrow=False,
            )
fig.add_annotation(x=0.3, y=0.625, #Q3
            text="Q3: 0.6",
            font=dict(size=16),
            showarrow=False,
            )
fig.add_annotation(x=0.33, y=0.332, #Median
            text="Median: 0.333",
            font=dict(size=16),
            showarrow=False,
            )
fig.add_annotation(x=0.3, y=0.24, #Q1
            text="Q1: 0.23",
            font=dict(size=16),
            showarrow=False,
            )
fig.add_annotation(x=0.3, y=0.2, #Min
            text="Min: 0.2",
            font=dict(size=16),
            showarrow=False,
            )
fig.update_traces(hoverinfo='skip')
fig.update_layout(
    title="Boxplot of parameters A",
    xaxis_title="A",
    yaxis_title="A Parameters")

fig.show()

1 Like

This works amazing thanks a lot!!

1 Like