jmquintana79
3/8/2017 - 12:19 AM

Plot line of boxplot distributions.

Plot line of boxplot distributions.

import matplotlib.pyplot as plt
import numpy as np

## Generate some data...
# matrix 2x2 of random values for line-boxplot
data = np.random.random((100, 5))
# y values for line
y = data.mean(axis=0) 
# x values for line
x = np.random.random(y.size) * 10 
x -= x.min()
x.sort()

# Plot a line between the means of each dataset
plt.plot(x, y, 'b-')

# Save the default tick positions, so we can reset them...
locs, labels = plt.xticks() 

# Plot box plot per each line point
plt.boxplot(data, positions=x, notch=True)

# Reset the xtick locations.
plt.xticks(locs)
# Plot
plt.show()