python - matplotlib/ Pandas : put line label along the plotted lines in time series plot

标签 python pandas matplotlib

我正在绘制比较来自多个节点的系统特征的时间序列数据。我想沿着它的线明确地标记来自特定节点的线。到目前为止,我已经成功地为特定节点放置了单独的线条样式,这在图例框中为其赋予了独特的线条和独特的样式标记。

我正在尝试找到一种方法来沿线放置独特的标签,可能是沿线弯曲的文本。有什么办法可以实现吗?

最佳答案

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

enter image description here

关于python - matplotlib/ Pandas : put line label along the plotted lines in time series plot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15210520/

相关文章:

python - Python 中的 Gamma 函数图

python - Google App Engine SSL 版本 2.7.11 库不受/支持

python - 将数据框对角线对齐到列中?

python - 如何使我的 pylab.poly1d(fit) 通过零?

python - Pandas 两个excel列比较中的一对多比较?

python - 访问 pandas dataframe 的正确方法

Python: 'numpy.ndarray' 对象没有属性 'violinplot'

python - OpenCV 和 python/virtualenv?

python - 快速搜索文本

python - 循环Python脚本如何检测当前时间是否在某个小时:minute time range?