x, y, = np.arange(10), np.arange(10)
for a in range(3):
plt.plot(x, a*y, alpha=0.5, marker='${}$'.format(a), markersize=10, label=a)
plt.legend()
plt.show()
编辑
在曲线上仅打印一次编号
x, y, = np.arange(10), np.arange(10)
colors = ['teal', 'darkslateblue', 'orange']
for a in range(3):
plt.plot(x, a*y, c=colors[a])
plt.plot(x[a+3], a*y[a+3], alpha=0.5, marker='${}$'.format(a), markersize=10, label=a, c=colors[a])
plt.legend()
plt.show()
我的答案是基于this question
可以在matplotlib中使用latex数学符号。 由于$1$计为latex数学符号,因此可以将其用作标记
具有0,1,2的示例:
编辑
在曲线上仅打印一次编号
有一个很好的小程序包
matplotlib-label-lines
实现了这一点(代码是github上的here)安装此软件包后,您的代码可能如下所示:
这会给你类似的东西
您还可以在图例中选择不同的线条样式,而不是颜色。
相关问题 更多 >
编程相关推荐