%pylab inline
Populating the interactive namespace from numpy and matplotlib
from beeswarm import *
import numpy as np
d1 = np.random.normal(size=100)
beeswarm([d1], method="swarm");
beeswarm([d1], method="hex");
beeswarm([d1], method="center");
beeswarm([d1], method="square");
beeswarm(d1);
beeswarm([d1, d1]);
beeswarm([d1]*4);
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"]);
beeswarm([d1,d2,d2], xlim=(-2,5), ylim=(-6,6));
beeswarm([d1,d2,d2], xlim=(-2,5));
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")
<matplotlib.text.Text at 0x4bb6ad0>
bs.head()
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
beeswarm([])
beeswarm([d1], positions=[])
ERROR: number of positions must match number of groups
beeswarm([d1], method="dummy")
ERROR: Invalid method.
beeswarm([d1], col=2)
ERROR: Invalid argument for col
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")