I want to create a plot showing a bunch of different time intervals which are all half open. Plotting the ranges themselves is easy enough, but what I'd like to be able to do is specify a line style that automatically plots the brackets and parentheses to signify that the interval is half open, without needing to manually plot them separately, or place text.
Currently using Matplotlib, but am open to using other libraries if that makes the problem easier.
I'm not sure there's such a function, but you could always create one, for example:
import matplotlib as mpl
import matplotlib.pyplot as plt
def add_interval(ax, xdata, ydata, caps=" "):
line = ax.add_line(mpl.lines.Line2D(xdata, ydata))
anno_args = {
'ha': 'center',
'va': 'center',
'size': 24,
'color': line.get_color()
}
a0 = ax.annotate(caps[0], xy=(xdata[0], ydata[0]), **anno_args)
a1 = ax.annotate(caps[1], xy=(xdata[1], ydata[1]), **anno_args)
return (line,(a0,a1))
fig, ax = plt.subplots()
add_interval(ax, (3,7), (3,3), "()")
add_interval(ax, (2,6), (2,2), "[]")
add_interval(ax, (1,5), (1,1), "(]")
plt.xlim((0,8))
plt.ylim((0,4))
plt.show()
Produces:
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