Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple way for using multiple Numpy Arrays as an input for one Seaborn boxplot

Most of the examples I found use Pandas DataFrame in order to have multiple boxes in a single box plot. I would like to know if there is a simpler, more straight forward way by directly using numpy arrays as the input.

For example, let's take five numpy arrays with each one of them having 20 entries. I would like to plot those five arrays as individual blocks next to each. The block should illustrate the variance of the array entries.

The end result should look something like the second picture on Seaborn's page.

like image 809
hlzl Avatar asked Mar 05 '18 19:03

hlzl


1 Answers

Simply pass a list of numpy arrays into seaborn's boxplot as it mentions from your very link, the data argument can consist of:

data : DataFrame, array, or list of arrays, optional

import numpy as np
import seaborn as sns

np.random.seed(111)

all_arr = [np.random.uniform(size=20),
           np.random.uniform(size=20),
           np.random.uniform(size=20),
           np.random.uniform(size=20),
           np.random.uniform(size=20)]

sns.boxplot(data=all_arr)

Numpy Array BoxPlot Output

like image 200
Parfait Avatar answered Oct 15 '22 02:10

Parfait