6
$\begingroup$

I am using the seaborn violin plot feature however the size of the violins aren't what I would expect them to be. Does anyone know whether this is something I am doing wrong, or as I suspect whether this is a bug in seaborn.

The code I am using is the following;

 sns.violinplot(x = "Issue Type", y = "issue_adj_risk_score", data=subset, scale="count", cut =0)

and the chart I can see is like this

enter image description here

As I understand it, becuase I have used the scale ="count" parameter, the sizes of each of these violins should be proportional to an overall count of the number of things in each area. In 'category 1' however (pink) I have a total of 936 with an issue_adj_risk_score of 1 whilst in category 2 (orange) I have a total of 1212 with an issue_adj_risk_score of 1.

I am confused however as the pink is larger than the orange! :-(

Does anyone know why this might be?

EDIT

I am now seeing further problems where the range of a particular category is inconsistent. I have a dataset and used violinplot to plot the below

enter image description here

Here we can see that a certain category (which I have highlighted in red) has a range from 1-4. This surprised me so I looked into the underlying data and it doesn't contain any values at 4. I then took a subset that contained this category only and plotted a violinplot with the same data and got this

enter image description here

Which is what I would have expected to see in the initial chart!

To investigate this further I plotted a boxplot based on the original data once again, and got the following

enter image description here

Which is consistent with the first chart but doesn't reflect the actual data. How can all of these 3 charts come from the same data!!??

| improve this question | | | | |
$\endgroup$
  • 4
    $\begingroup$ Can you provide the dataset for the visualization? $\endgroup$ – tuomastik Aug 8 '17 at 19:45
  • $\begingroup$ You should add your dataset as @tuomastik mentioned. Otherwise people can't answer... $\endgroup$ – Blaszard Aug 12 '17 at 2:19
  • $\begingroup$ The dataset is a bit big to add on here. I could do some aggregation, however I am now seeing a similar problem where the violin for a category has a totally different range when created from different DataFrames, despite the data being exactly the same. $\endgroup$ – Taylrl Aug 16 '17 at 10:36
  • $\begingroup$ It seems that the scale = "count" option doesn't actually give a representation based on the overall "count" and whilst the data is properly represented, the labels don't match the data. $\endgroup$ – Taylrl Aug 16 '17 at 12:41
  • $\begingroup$ I am getting a similar problem with the R version. I split the violin plot in positive and negative side to describe a binary with a ratio of 2:1 but the area of each side does not follow this proportion. And, as it is in your case, the count modality does not work properly only for one of the categories I have. $\endgroup$ – Alessandro Cicchetti Apr 2 at 18:16
2
$\begingroup$

From the seaborn documentation:

scale : {“area”, “count”, “width”}, optional

The method used to scale the width of each violin. If area, each violin will have the same area. If count, the width of the violins will be scaled by the number of observations in that bin. If width, each violin will have the same width.

So the violins are scaled such that the width is proportional to the number of observations. You were expecting the area to be scaled with count, not the width, and that seems natural to me but that option does not seem to exist in seaborn. Here is an issue regarding this, with a handmade solution:

https://github.com/mwaskom/seaborn/issues/962

| improve this answer | | | | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.