This repository has been archived on 2021-05-17. You can view files and clone it, but cannot push or open issues or pull requests.
scientificComputing/statistics/lecture/boxwhisker.py

40 lines
1.5 KiB
Python

import numpy as np
import matplotlib.pyplot as plt
from plotstyle import *
rng = np.random.RandomState(981)
x = rng.randn( 40, 10 )
fig, ax = plt.subplots()
ax.set_xlabel('Experiment')
ax.set_ylabel('x')
ax.set_ylim(-4.0, 4.0)
ax.annotate('Median',
xy=(3.9, 0.0), xycoords='data',
xytext=(3.5, -2.7), textcoords='data', ha='right',
arrowprops=dict(arrowstyle="->", relpos=(0.8,1.0),
connectionstyle="angle3,angleA=-110,angleB=60") )
ax.annotate('1. quartile',
xy=(5.8, -0.9), xycoords='data',
xytext=(5.5, -3.4), textcoords='data', ha='right',
arrowprops=dict(arrowstyle="->", relpos=(0.9,1.0),
connectionstyle="angle3,angleA=30,angleB=70") )
ax.annotate('3. quartile',
xy=(6.1, 1.1), xycoords='data',
xytext=(6.5, 3.0), textcoords='data', ha='left',
arrowprops=dict(arrowstyle="->", relpos=(0.0,0.0),
connectionstyle="angle3,angleA=30,angleB=70") )
ax.annotate('minimum',
xy=(6.1, -1.9), xycoords='data',
xytext=(7.2, -3.3), textcoords='data', ha='left',
arrowprops=dict(arrowstyle="->", relpos=(0.0,0.5),
connectionstyle="angle3,angleA=10,angleB=100") )
ax.annotate('maximum',
xy=(5.9, 2.7), xycoords='data',
xytext=(4.9, 3.5), textcoords='data', ha='right',
arrowprops=dict(arrowstyle="->", relpos=(1.0,0.5),
connectionstyle="angle3,angleA=0,angleB=120") )
ax.boxplot(x, whis=100.0)
plt.savefig('boxwhisker.pdf')