Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text on the left side of the symbol in matplotlib legend [duplicate]

Is there any built-in function/method or concise way to bring the text on left side of marker/symbol in legend?

like image 637
Malik Avatar asked Sep 11 '25 16:09

Malik


1 Answers

this can be done by setting the parameter markerfirstof the matplotlib.pyplot.legend to False.

markerfist : bool If True, legend marker is placed to the left of the legend label. If False, legend marker is placed to the right of the legend label. Default is True.

Something like that:

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

I hope this is what you were looking for :)

like image 69
youngpanda Avatar answered Sep 13 '25 05:09

youngpanda