Black Lives Matter. Please consider donating to Black Girls Code today.

Bubble charts with distinct bubbles (not-overlapping)

Hi Team,

I am creating a bubble chart but the bubbles are a little bit messy. How can I make them more distinct? If you can see in the screenshot below overlapping bubbles make it difficult to distinguish.

My code is:

for type_name, economic_type in type_data.items():
        x=economic_type['Risk'], y=economic_type['Return_6m'],
        name=type_name, text=economic_type['ISO CODE'],

fig.update_traces(mode='markers+text', marker=dict(sizemode='area',
                                              sizeref=sizeref, line_width=1, line_color='white', opacity=0.35 ))

Thanks for your help.


Hi @vgelis did you try to increase the marker_line_width parameter?

HI @Emmanuelle,

It does not seem to work. I increased the marker width and made the opacity =1 but the bubbles are still not distinct. Is there a way to specify the small bubbles to be always on top of the bigger ones?


The easiest is probably to sort your data by decreasing order before plotting them, for example

import numpy as np
import as px
x = np.array([1, 1, 1])
y = np.array([1, 1, 1])
size = np.array([1, 4, 9])
order = np.argsort(size)[::-1] 
fig = px.scatter(x=x[order], y=y[order], size=size[order], size_max=100)
fig.update_traces(marker_line_width=2, marker_line_color='white')

Thanks for the help :slight_smile: