I am plotting time series data comparing system characteristics from multiple nodes. I want to label the line from a particular node explicitly along its line. So far I have succeeded in putting separate line style for the particular node, which gives it distinctive line and distinctive style marker in the legend box.
I am trying to find a way to put distinctive label along the line, possibly text curving along the line. Any way to achieve that?
You can set the labels on that object. Or, more succinctly: ax. set(xlabel="x label", ylabel="y label") . Alternatively, the index x-axis label is automatically set to the Index name, if it has one.
To create a time series plot, we can use simply apply plot function on time series object and if we want to create a vertical line on that plot then abline function will be used with v argument.
Text curving along the line isn't easy to do with matplotlib, but annotate
will allow you to easily label the line with text and an arrow.
E.g.
import matplotlib.pyplot as plt
import numpy as np
# Generate some data
x = np.linspace(0, 20, 200)
y = np.cos(x) + 0.5 * np.sin(3 * x)
fig, ax = plt.subplots()
ax.plot(x, y)
ax.annotate(r'$y = cos(x) + \frac{sin(3x)}{2}$', xy=(x[70], y[70]),
xytext=(20, 10), textcoords='offset points', va='center',
arrowprops=dict(arrowstyle='->'))
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