I'm trying to plot multi intervals for multiple entries.
I've tried using a loop to enumerate over the entries, plotting one interval at a time.
import matplotlib.pyplot as plt
intervals = [(1, 2), (1.1, 2.5), (1.2, 4), (1.5, 10), (1.7, 12)]
num_intervals = len(intervals)
viridis = plt.cm.get_cmap('viridis', num_intervals)
fig, ax = plt.subplots()
for idx, (min_int, max_int) in enumerate(intervals):
ax.hlines(y=idx, xmin=min_int, xmax=max_int, colors=viridis(idx / num_intervals), label=idx)
ax.legend()
plt.yticks([], [])
plt.show()
I wish to use matplotlib's build-in method for plotting multiple intervals all at once. Also, I wish to plot the min and max values for each interval in the image.
I wish to add min & max values annotations to the lines as such: