Matplotlib / pandas: place a line label along the drawn lines in the time series chart

I draw time series data by comparing system characteristics with multiple nodes. I want to mark a line from a specific node explicitly along my line. So far, I have managed to place a separate line style for a particular node, which gives it a distinctive line and a distinctive style marker in the legend field.

I am trying to find a way to place a distinctive mark along a line, perhaps bending text along a line. Any way to achieve this?

+5
source share
1 answer

Text curvature along a line is not easy to do with matplotlib, but annotatewill allow you to easily mark a line with text and an arrow.

eg.

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()

enter image description here

+5
source

All Articles