0

I am trying to show box-plot of some Ratings data from a Pandas DataFrame. I want to get meanline shown in Box-plot. When I pass meanline=True, the line shows as doted but when I pass parameter linestyle='-' or linestyle='--' or however in other way it shows an error

TypeError: boxplot() got an unexpected keyword argument 'linestyle'

My code is

sns.boxplot(x="rating", data=df, whis=5, color='None', showmeans=True, meanline=True, linestyle='-', linewidth=5)

If I remove color parameter, it's default color shows that's almost faded blue. But when I pass color='None' then it shows box as black and meanline is at least visible then. I have tried a lot of different combinations of parameters to check if it works but in vein.

Now, I want

  • Full meanline not doted in black color so that it will be clearly visible

Remember! the main issue is that error with linestyle parameter not with the designing of Box. Hope so I explained it enough

ARHAM RUMI
  • 441
  • 5
  • 11
  • 2
    I think the error is quite self explanatory, there is no `linestyle` parameter in box plot. – mozway Aug 23 '21 at 20:02
  • @mozway I know that what it is saying, but when I searched for it on different places, even on stackoverflow, many of the developers used that – ARHAM RUMI Aug 23 '21 at 20:04
  • 2
    Does this answer your question? [How to edit properties of whiskers, fliers, caps, etc. in Seaborn boxplot](https://stackoverflow.com/q/36874697/7758804) – Trenton McKinney Aug 23 '21 at 20:05
  • @mozway See Ted Petruo's comment on this question. He said that he used it. https://stackoverflow.com/questions/46226032/how-to-change-the-linestyle-of-whiskers-in-pandas-boxplots – ARHAM RUMI Aug 23 '21 at 20:08
  • From what I read, the used approach is the `xxxprops={'subparam': 'value'}` one. Check [my answer](https://stackoverflow.com/a/68898431/16343464) and the linked [documentation](https://matplotlib.org/stable/gallery/statistics/boxplot.html) and posts for reference. Let us know if it worked. – mozway Aug 23 '21 at 20:12

1 Answers1

0

As there are many lines in a box plot you need to tell which one you want to customize. Use the meanprops={'linestyle': '-'} parameter.

sns.boxplot(x="rating", data=df, whis=5, color='None', showmeans=True, meanline=True, meanprops={'linestyle'='-', 'linewidth': 5})

Check the documentation on boxplot customization for further details.

mozway
  • 194,879
  • 13
  • 39
  • 75