79753254

Date: 2025-09-02 08:27:14
Score: 1.5
Natty:
Report link

I tried this :

ax = sns.swarmplot(data=df, x="value", y="letter", log_scale=2, hue="type", palette=my_palette, size=6)

collection = ax.collections[0]
offsets = collection.get_offsets()

xy_stars = []
# Select first 15 offset (stars)
i = 0
for (x, y) in offsets:
    if i < 15:
        xy_stars.append([x,y])
        ax.scatter(x - 0.000001, y, s=40, color='#944dff', marker=(5, 1), zorder=100)
    i += 1

x_stars = [xs[0] for xs in xy_stars]

for collection in ax.collections:
    offsets = collection.get_offsets()

    # Removes 'star' scatters
    new_offsets = [offset for offset in offsets if offset[0] not in x_stars]

    # Update offsets collection
    collection.set_offsets(new_offsets)

enter image description here

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Benoit Wernerus