How to make geom_jitter like plot with Plotly with Python?

Like the plot below, it’s made by R geom_jitter package, which is good for me.

I’d like to plot with Plotly (the python version), and I searched all the gallery, but don’t find a good one demo.

I can use scatter, but the result is not so good(as below), maybe there are some configs about scatter which I don’t know? Please help~

Hi @a3801283,

Here’s an approach using the violin trace that comes pretty close:

from plotly.offline import iplot, init_notebook_mode
import plotly.graph_objs as go
# init_notebook_mode() # uncomment in classic notebook

import pandas as pd

df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/violin_data.csv")

data = []
for i in range(0,len(pd.unique(df['day']))):
    trace = {
            "type": 'violin',
            "x": df['day'][df['day'] == pd.unique(df['day'])[i]],
            "y": df['total_bill'][df['day'] == pd.unique(df['day'])[i]],
            "name": pd.unique(df['day'])[i],
            "fillcolor": 'lightgray',
            "points": 'all',
            "jitter": 1.0,
            "pointpos": 0
        }
    data.append(trace)

fig = go.Figure({
    "data": data,
    "layout" : {
        "title": "",
        "yaxis": {
            "zeroline": False,
        }
    }
})
iplot(fig)

Check out the this page for more violin examples.

Hope that helps!
-Jon

2 Likes

Thanks so much~

It seems the ggplot2 plot is more attractive.