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

Violin plot - constrain distribution to within data bounds

Hello all,

I was wondering if there is a way to constrain the distribution shown on a violin plot to be within the bounds of the data that is being plotted. What I am looking for is something like seaborns ‘cut’. Basically, I want to constrain the distribution curve generated by the violin plot to have the same max and min value as my data.

Hi @purpleboy
You can restrict plotting the pdf to a given range, using the attributes span, and spanmode.
span is a list of two values span =[start, end] and spanmode = 'manual'


import pandas as pd

df = pd.read_csv("")

fig = go.Figure(data=go.Violin(y=df['total_bill'],  line_color='black', 
                               meanline_visible=True, fillcolor='lightseagreen', opacity=0.6,
                               x0='Total Bill'))

fig.update_layout(yaxis_zeroline=False, width=500)

Now update[0] setting span and spanmode:[0].update(span = [10, 40], spanmode='manual');