Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add swarm plot #5087

Open
suterberg opened this issue Mar 14, 2025 · 1 comment
Open

add swarm plot #5087

suterberg opened this issue Mar 14, 2025 · 1 comment
Labels
feature something new P3 backlog

Comments

@suterberg
Copy link

I can't find swarm plot in plotly, but can use this way to plot a swarm map:

import plotly.express as px
import numpy as np
import pandas as pd

np.random.seed(1)
y0 = np.random.randn(50) - 1

mm=pd.DataFrame({"org":y0})
tmp=[]
for k in y0:
    tmp.append(np.floor(k*10)/10)
mm["cut"]=tmp
cc=pd.DataFrame(columns=["x","y"])
width=0.08
for s in mm.groupby("cut"):
    # print(type(s))
    x=s[0]
    mp=s[1]
    ls=len(s[1])
    mid= int(ls/2)
    org= -mid
    if ls%2==0:
        org=org+0.5
        for i in range(ls):
            cc.loc[len(cc)]=[x,(i+org)*width]
        # for i in range(ls):
        #     if i == mid:
        #         org=org+1
        #     cc.loc[len(cc)]=[x,(i+org)*width]
    else:
        for i in range(ls):
            cc.loc[len(cc)]=[x,(i+org)*width]
  
# print(mm)
# print(cc)

fig = px.scatter(cc,x='x',y='y',range_y=[-2,2])
# fig=px.strip(cc,x='x',y='y',range_y=[-2,2])

fig.show()

this is a example for how to deal data and transform data for swarm
Image

@gvwilson gvwilson changed the title Swarm plot add swarm plot Mar 17, 2025
@gvwilson gvwilson added feature something new P3 backlog labels Mar 17, 2025
@gvwilson
Copy link
Contributor

thanks @suterberg - have you posted this to our forums https://community.plotly.com/ as well? you may get a faster response there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature something new P3 backlog
Projects
None yet
Development

No branches or pull requests

2 participants