import numpy as np
import matplotlib.pyplot as plt
# Create the data
mr_m = [525.8, 605.7, 843.3, 1195.5, 1945.6, 2135.6, 2308.7, 2950]
mr_f = [727.7, 1086.5, 1091, 1361.3, 1490.5, 1956.1]
mean_f = np.mean(mr_f)
mean_m = np.mean(mr_m)
std_f = np.std(mr_f)
std_m = np.std(mr_m)
# Create a figure
fig = plt.figure()
ax = fig.add_subplot(111)
# Set Layout
ax.set_xlim([0.4, 2.6])
ax.set_xticks([1, 2])
ax.set_xticklabels(['Female', 'Male'])
ax.set_ylabel('Metabolic Rate')
# Plot the data
ax.plot(np.ones_like(mr_f), mr_f, 'ko') # k -> blacK, o-> plot just the datapoints
ax.plot(2 * np.ones_like(mr_m), mr_m, 'ko')
ax.plot(1, mean_f, 'ro')
ax.plot(2, mean_m, 'ro')
# Plot the arrows and the text with *annotate()*, some tuning on the values
# necessary to get the right offsets
# *annotate()* calls *FancyArrowPatch* to plot the arrows, could be used directly
ax.annotate('', xy=(1.1, mean_f - std_f / 2),
xytext=(1.1, mean_f + std_f / 2),
arrowprops=dict(arrowstyle='<->', color='r'))
ax.annotate('Female\nStd. Dev.={}'.format(int(std_f)), xy=(1.15, mean_f -100))
ax.annotate('', xy=(2.1, mean_m - std_m / 2),
xytext=(2.1, mean_m + std_m / 2),
arrowprops=dict(arrowstyle='<->', color='r'))
ax.annotate('Male\nStd. Dev.={}'.format(int(std_m)), xy=(2.15, mean_m -100))