Search code examples
pythonmatplotlibtypeerrorviolin-plot

TypeError: violinplot() got an unexpected keyword argument 'quantiles'


I'm trying to make a violin plot that shows the 0.25 and 0.75 quantiles, but keep getting a TypeError, despite the documentation suggesting this is a valid keyword.

Here is my code:

grid = plt.GridSpec(1, 1, wspace=0.15, hspace=0.1)

plotplag = fig.add_subplot(grid[0,0])

plotplag.set_xticks([1,2,3,4,5,6,7,8])
plotplag.violinplot([S95BCore_an, S95BRim_an, S98Core_an, S98Rim_an, VHCoreLZ_an, VHRimLZ_an, VHCoreUZ_an, VHRimUZ_an], showmeans=True, quantiles=[[0.75], [0.25]])
plotplag.set_xticklabels(['S95B Core', 'S95B Rim', 'S98 Core', 'S98 Rim', 'MS LZ Core', 'MS LZ Rim', 'MS UZ Core', 'MS UZ Rim'])

plotplag.set_ylabel('An# (mol. %)', fontsize=16)

Solution

  • Have you tried quantiles = [0.75, 0.25] instead of quantiles=[[0.75], [0.25]] ? Going off of examples here: https://matplotlib.org/devdocs/gallery/statistics/violinplot.html

    It could also be a version issue: from the command line try:

    $ pip install -U matplotlib