This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def jitterplot(x, data, ax): | |
# x: position on x-axis | |
# data: datapoins in the box | |
# ax: specified ax | |
np.random.seed(0) | |
for c in range(len(data)): | |
ax.plot(np.random.normal(x-0.08,0.08), data[c], '.',color='grey',markersize=12, markeredgecolor='k',label=labels[c]) | |
data = # array of list of datapoints. each list corresponds to a box. | |
names = # box names | |
fig, ax = plt.subplots(1,1) | |
_= ax.boxplot(data,showfliers=False) | |
_= ax.set_xticks(range(1,len(data)+1)) | |
_= ax.set_xticklabels(names) | |
plt.setp(ax.get_xticklabels(), rotation=60, ha="right",rotation_mode="anchor") | |
for i,name in enumerate(names): # loop across boxes | |
jitterplot(i+1,data[i],ax) | |
ax.legend() |