6

我正在绘制比较来自多个节点的系统特性的时间序列数据。我想沿其线显式标记来自特定节点的线。到目前为止,我已经成功地为特定节点设置了单独的线条样式,这使其在图例框中具有独特的线条和独特的样式标记。

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

4

1 回答 1

5

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

在此处输入图像描述

于 2013-03-05T01:48:48.943 回答