Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues faceting violinplots / boxplots #177

Closed
sjobeek opened this issue Apr 23, 2014 · 10 comments
Closed

Issues faceting violinplots / boxplots #177

sjobeek opened this issue Apr 23, 2014 · 10 comments

Comments

@sjobeek
Copy link

sjobeek commented Apr 23, 2014

I ran into a KeyError while attempting to facet a single violinplot into each plot of a FacetGrid.

Here is some short code that replicated the problem:

df = pd.DataFrame(dict(one=[1,2,4,2,3], two=[2,2,4,4,4], three=[1,1,1,2,2]))
fg = sns.FacetGrid(df, col='three')
fg.map(sns.boxplot, 'one')

Supplying a second parameter ('groupby') results in the proper plots, even if there is only a single group.

I'd expect the single plot to simply work. Perhaps violinplot/boxplot is expecting a continuous index if given a dataframe?

@sjobeek
Copy link
Author

sjobeek commented Apr 23, 2014

There also seems to be some other problems with the locations of the labels, and the actual grouping of the data when faceting.

While a single plot works as expected:

df = pd.DataFrame(dict(one=[1,2,4,2,1,3], two=[1,1,2,2,4,4], three=[1,1,1,1,2,2]))
sns.violinplot(df.one, df.two)

index1

a FacetGrid with the same data will fail to group it or apply the labels where I expect them (one / two are switched):

fg = sns.FacetGrid(df, col='three')
fg.map(sns.violinplot, 'one', 'two')

index2

And finally, inner='sticks' doesn't appear to actually draw any sticks when I've tried to use it, though 'points' is working properly.

@sjobeek sjobeek changed the title Faceting violinplots / boxplots Issues faceting violinplots / boxplots Apr 23, 2014
@mwaskom
Copy link
Owner

mwaskom commented Apr 24, 2014

Yeah, basically the dilemma here is that I either have to break the API of voilinplot/boxplot or they don't get to work with FacetGrid. I punted on this decision for 0.3 (although there is a kind="box" in factorplot that somewhat gets around the issue (example here).

@sjobeek
Copy link
Author

sjobeek commented Apr 24, 2014

I've also noticed that violinplots run into an LinAlgError: singular matrix exception if any single plot has several instances of a single value.

This means I can't use it to compare a large collection of relatively sparse datasets that may or may not have a single "facet" with repeat values. Obviously it's not possible to actually calculate a KDE if there is 0 variation, but it would be nice if we could at least continue to plot the rest of the data without completely failing.

I find violinplots with inner='points' to be quite useful for visually comparing large sets of data with just 3-5 datapoints each. Unfortunately this bug makes it unfeasible for many datasets which have a small chance of seeing zero variation for a single facet.

@harper357
Copy link

I am also running into the LinAlgError: singular matrix exception. Is there any hope of a fix/work around/exception for it? It would be nice if, like sjobeek said, it could continue to plot the rest of the data.

@mwaskom
Copy link
Owner

mwaskom commented Nov 19, 2014

What version of seaborn do you have? I'm pretty sure I've fixed this.

@harper357
Copy link

I have 0.5.0.

@mwaskom
Copy link
Owner

mwaskom commented Nov 19, 2014

It's possible you are seeing something else, then, this works for me:

screenshot 2014-11-18 20 08 44

@harper357
Copy link

I tried repeating your last post and I got the same thing you did. The problem I am having, and maybe it is actually something different, is if you have only have one value repeated. So
data = [np.random.randn(100), [.83,.83,.83]]
will give the error.

@mwaskom
Copy link
Owner

mwaskom commented Nov 19, 2014

Can you make a separate issue with a self-contained example so it's easier to keep track of?

@mwaskom
Copy link
Owner

mwaskom commented Jan 19, 2015

Closing with #410

@mwaskom mwaskom closed this as completed Jan 19, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants