有没有内置的函数/方法或简洁的方式可以将图例中标记/符号左侧的文本带出?
可以通过将matplotlib.pyplot.legend
的参数markerfirst
设置为False
来实现。
markerfirst : bool 如果为True,图例标记将放置在图例标签左侧。如果为False,则图例标记将放置在图例标签右侧。默认值为True。
类似这样:
t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2 * np.pi * t)
fig, ax = plt.subplots()
ax.plot(t, s, label='sine')
ax.legend(markerfirst=False)
plt.show()