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.
image
1165×591 84.4 KB
My code is:
for type_name, economic_type in type_data.items():
fig.add_trace(go.Scatter(
x=economic_type['Risk'], y=economic_type['Return_6m'],
name=type_name, text=economic_type['ISO CODE'],
marker_size=economic_type['Cap_USD'],marker_color=economic_type['Color']))
fig.update_traces(mode='markers+text', marker=dict(sizemode='area',
sizeref=sizeref, line_width=1, line_color='white', opacity=0.35 ))
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?
image1090×457 24.2 KB
Thanks,
Evangelos
The easiest is probably to sort your data by decreasing order before plotting them, for example
import numpy as np
import plotly.express 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')
image1020×630 16.6 KB