I'm trying to combine a normal matplotlib.pyplot plt.plot(x,y)
with variable y
as a function of variable x
with a boxplot. However, I only want a boxplot on certain (variable) locations of x
but this does not seem to work in matplotlib?
Are you wanting something like this? The positions
kwarg to boxplot
allows you to place the boxplots at arbitrary positions.
import matplotlib.pyplot as plt
import numpy as np
# Generate some data...
data = np.random.random((100, 5))
y = data.mean(axis=0)
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()
plt.boxplot(data, positions=x, notch=True)
# Reset the xtick locations.
plt.xticks(locs)
plt.show()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With