如果我理解正確的話,你可以用一個簡單的errorbar情節做到這一點(雖然這是一個黑客位的):
import numpy as np
import matplotlib.pyplot as plt
# 20 random samples
nsamples = 20
xmin, xmax = 0, 150
samples = np.random.random_sample((nsamples,2)) * (xmax-xmin) + xmin
samples.sort(axis=1)
means = np.mean(samples, axis=1)
# Find the length of the errorbar each side of the mean
half_range = samples[:,1] - means
# Plot without markers and customize the errorbar
_, caps, _ = plt.errorbar(means, np.arange(nsamples)+1, xerr=half_range, ls='',
elinewidth=3, capsize=5)
for cap in caps:
cap.set_markeredgewidth(3)
# Set the y-range so we can see all the errorbars clearly
plt.ylim(0, nsamples+1)
plt.show()
來源
2015-11-20 13:19:07
xnx
謝謝你這麼多,我覺得這是什麼我需要。如果遇到問題,我會回到這裏。 – Ian