Reputation: 1716
I am trying to visualize a set of frequency ranges for around 20 samples I have. What I want to do is a horizontal bar chart where each row represents one sample. The sample name is supposed to go on the left and on the right I want an x-axis with limits 0 and 150 kHz.
Now the ranges I have are something like (70.5, 95.5). Can I realize this with a horizontal bar chart or am I looking for a different type of chart?
Sorry that I can't provide an example, because I just got nothing so far. A bar chart just doesn't do what I want.
Edit: I basically want something like in this example but without the actual bars and with being able to enter my data for the error bars. As far as I know error bars can only work with errors relative to the "main data".
Upvotes: 1
Views: 3597
Reputation: 25548
If I understand you correctly, you can do this with a simple errorbar plot (though it's a bit of a hack):
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()
Upvotes: 3