In [1]:
%pylab inline


Populating the interactive namespace from numpy and matplotlib

In [2]:
from beeswarm import *
import numpy as np

In [3]:
d1 = np.random.normal(size=100)

Test arrangement methods


In [4]:
beeswarm([d1], method="swarm");



In [5]:
beeswarm([d1], method="hex");



In [6]:
beeswarm([d1], method="center");



In [7]:
beeswarm([d1], method="square");


Test input methods


In [8]:
beeswarm(d1);



In [9]:
beeswarm([d1, d1]);



In [10]:
beeswarm([d1]*4);



In [11]:
d2 = np.random.uniform(low=-5, high=0, size=100)
beeswarm([d1,d1,d2], positions=[1,2, 5], labels=["test1","test2","test3"], col=["red","green","orange"]);


Test axis methods


In [12]:
beeswarm([d1,d2,d2], xlim=(-2,5), ylim=(-6,6));



In [13]:
beeswarm([d1,d2,d2], xlim=(-2,5));



In [14]:
fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_xlim(left=-2, right=6)
ax.set_ylim(bottom=-10, top=10)
bs, ax = beeswarm([d1,d1,d2,d2], positions=[0,3,5,6], ax=ax, col=["red","orange","yellow"]);
ax.set_xlabel("testing x")


Out[14]:
<matplotlib.text.Text at 0x4bb6ad0>

In [15]:
bs.head()


Out[15]:
color xnew xorig ynew yorig
0 red 0.000000 0 -3.233790 -3.233790
1 orange 0.000000 0 -2.594117 -2.594117
2 yellow 0.000000 0 -2.362106 -2.362106
3 red 0.000000 0 -1.962170 -1.962170
4 orange 0.123496 0 -1.955887 -1.955887

5 rows × 5 columns

Try to break it


In [16]:
beeswarm([])

In [17]:
beeswarm([d1], positions=[])


ERROR: number of positions must match number of groups

In [18]:
beeswarm([d1], method="dummy")


ERROR: Invalid method.

In [19]:
beeswarm([d1], col=2)


ERROR: Invalid argument for col

Make a pretty one


In [20]:
d1 = np.random.normal(size=100)
d2 = np.random.normal(loc=1, size=100)
d3 = np.random.normal(scale=2, size=100)
d4 = np.random.uniform(low=-3, high=3, size=100)

bs, ax = beeswarm([d1,d2,d3,d4], col=["red","orange","yellow"], labels=["N(0,1)", "N(1,1)", "N(0,2)","Unif(-3,3)"])
ax.set_xticklabels(["N(0,1)", "N(1,1)", "N(0,2)","Unif(-3,3)"], size=15);
ax.set_yticklabels(np.arange(-4,7,2), size=15);
plt.savefig("example.png")