Search code examples
pythonmatplotlibseaborndata-sciencevisualization

`inner_kws` having no effect on Seaborn violin plot


I generated a bunch of violin plots, here is an example of one and the code that generates it:

plt.figure(figsize=(8, 4))
ax = sns.violinplot(
    x=data, # `data` is a few thousand float values between 0 and 1
    orient='h',
    color=get_color(ff), # `get_color` returns a color based on the dataset, #FFBE0B in this case
    cut=0
)

a purple violin plot

I want to make the black box in the middle quite a bit bigger. According to the documentation from Seaborn at https://seaborn.pydata.org/generated/seaborn.violinplot.html, I should be able to do this with the inner_kws parameter. I added this argument to the above code:

plt.figure(figsize=(8, 4))
ax = sns.violinplot(
    x=data, # `data` is a few thousand float values between 0 and 1
    orient='h',
    color=get_color(ff), # `get_color` returns a color based on the dataset, #FFBE0B in this case
    inner_kws=dict(box_width=150, whis_width=20),
    cut=0
)

Above, the box and whisker width are 150 and 20 respectively. I've also tried 15 and 2, and 1500 and 200. No matter what values I enter here, the figure does not change at all. What am I doing wrong?


Solution

  • The inner_kws argument was introduced in version 0.13.0; if you have an older version of seaborn installed it has no effect. I had seaborn v0.12.2 (installed via conda) and your example printed with normal boxplot dimensions until I upgraded seaborn to v0.13.2,

    E.g.

    #!/usr/bin/env python
    
    import random
    import seaborn as sns
    import matplotlib.pyplot as plt
    
    data = []
    for i in range(0, 1000):
        x = round(random.uniform(0, 1), 4)
        data.append(x)
    
    ax = sns.violinplot(
        x=data, # `data` is a few thousand float values between 0 and 1
        orient='h',
        color='#FFBE0B',
        inner_kws=dict(box_width=100, whis_width=20),
        cut=0
    )
    
    plt.savefig("example.png")
    

    python_plot.png

    Does that solve your problem? Or is there something else causing an issue?