我正在绘制比较来自多个节点的系统特征的时间序列数据。我想沿着它的线明确地标记来自特定节点的线。到目前为止,我已经成功地为特定节点放置了单独的线条样式,这在图例框中为其赋予了独特的线条和独特的样式标记。
我正在尝试找到一种方法来沿线放置独特的标签,可能是沿线弯曲的文本。有什么办法可以实现吗?
最佳答案
使用 matplotlib 不容易实现沿线弯曲的文本,但是 annotate
可以让您轻松地用文本和箭头标记线。
例如
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()
关于python - matplotlib/ Pandas : put line label along the plotted lines in time series plot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15210520/