Wednesday, 15 May 2013

matplotlib - Python: create multiple boxplots in one pannel -



matplotlib - Python: create multiple boxplots in one pannel -

i have been using r long time , learning python. create multiple box plots in 1 panel in python. dataset in vector form , label vector indicates box plot each element of info corresponds. illustration looks this:

n = 50 info = np.random.lognormal(size=n, mean=1.5, sigma=1.75) label = np.repeat([1,2,3,4,5],n/5)

from various websites (e.g., matplotlib: grouping boxplots), creating multiple boxplots requires matrix object input column contains samples 1 boxplot. created list object based on info , label:

savelist = data[ label == 1] in [2,3,4,5]: savelist = [savelist, data[ label == i]]

however, code below gives me error:

boxplot(savelist) traceback (most recent phone call last): file "<ipython-input-222-1a55d04981c4>", line 1, in <module> boxplot(savelist) file "/users/yumik091186/anaconda/lib/python2.7/site-packages/matplotlib/pyplot.py", line 2636, in boxplot meanprops=meanprops, manage_xticks=manage_xticks) file "/users/yumik091186/anaconda/lib/python2.7/site-packages/matplotlib/axes/_axes.py", line 3045, in boxplot labels=labels) file "/users/yumik091186/anaconda/lib/python2.7/site-packages/matplotlib/cbook.py", line 1962, in boxplot_stats stats['mean'] = np.mean(x) file "/users/yumik091186/anaconda/lib/python2.7/site-packages/numpy/core/fromnumeric.py", line 2727, in mean out=out, keepdims=keepdims) file "/users/yumik091186/anaconda/lib/python2.7/site-packages/numpy/core/_methods.py", line 66, in _mean ret = umr_sum(arr, axis, dtype, out, keepdims) valueerror: operands not broadcast shapes (2,) (10,)

can explain going on?

you're ending nested list instead of flat list. seek instead:

savelist = [data[label == 1]] in [2,3,4,5]: savelist.append(data[label == i])

and should work.

python matplotlib boxplot

No comments:

Post a Comment