4

I have recently updated my seaborn from 0.5.1 to the new 0.6.0 version. I had been using seaborn to make box plots and violinplots in python notebookand now I can't seem to make my code work anymore. Matplotlib plt.boxplot still works with my data. Particularly, the problem seems to happen when I have a group of lists or arrays in which the subsets are different in size.

e.g.:

import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
x = np.array([1,3,4]), ([1,2])
plt.boxplot(x) #this works



 import numpy as np
 import matplotlib.pyplot as plt
 import seaborn as sns
 x = np.array([1,3,4]), ([1,2])
 sns.boxplot(x) #doesn't work

This is the error I get when I try the seaborn box plot

ValueError: List of boxplot statistics and `positions` values must have same the length

In the new seaborn tutorial, it says sns.boxplot should take everything that plt.boxplot does. Has anyone had the same problem with the update? Is there a way of making this work? If not, is there a way of installing both the 0.6.0 version and the 0.5.1 version and calling a specific version in certain notebooks?

hitzg
  • 12,133
  • 52
  • 54
salima
  • 43
  • 1
  • 3

1 Answers1

5

As discussed in the release notes there have been some changes to the API for categorical plots.

In your case, you just need to explicitly pass your list (tuple, technically) of arrays to the data parameter:

sns.boxplot(data=x)
mwaskom
  • 46,693
  • 16
  • 125
  • 127
  • Thanks! This works. Is there a way of adding x labels to the values? I haven't been able to do that either. – salima Jul 02 '15 at 16:51
  • If you use a DataFrame, the column names will be used as labels. See numerous examples here: http://stanford.edu/~mwaskom/software/seaborn/generated/seaborn.boxplot.html#seaborn.boxplot – mwaskom Jul 02 '15 at 16:58
  • 1
    Thanks. For the lists, I just figured I can use: x = np.array([1,3,4]), ([1,2]) box=sns.boxplot(data=x) box.set_xticklabels(['a','b']) – salima Jul 02 '15 at 17:07