Bring Drag & Drop to Dash with Dashboard Engine. 💫 Learn how at our next webinar!

How do I align text annotations to appear inside of scatterplot marker?

Hi

I’d like to place scatterplot marker annotations inside the actual plot marks. It is just a one or two digit number so it should fit if the text is small enough. However, I see no obvious way to configure it to appear inside the boundary of the individual marker. Here is an example of how I’d like it to look:

Thank you in advance for your feedback!

Simple solution inside the plot specs, just add a text= setting and value:

fig = px.scatter(df, x="X", y="Y", color="Team", hover_name="NickName", animation_frame="GameTime", animation_group="NickName", range_x=[-4,110], range_y=[-4,72], size='size', size_max=10,width=900, height=600, color_discrete_map=color_discrete_map, text='JerseyNumber')

Then set the marker text size small enough to fit inside the marker:

# Make jersey number really small inside markers
fig.update_traces(textfont_size=6)