Tohiko
Tohiko

Reputation: 1982

legends with text to the right of line styles

Is there a way in matplotlib to position the text in legend to the right of the line styles?

That is, I want a legend that looks like this

Legend with text

Thanks

Upvotes: 3

Views: 310

Answers (1)

ImportanceOfBeingErnest
ImportanceOfBeingErnest

Reputation: 339550

As seen from the legend documentation, there is a markerfirst argument which can be set to False to make the markers appear last.

plt.legend(markerfirst=False)

Full example:

import matplotlib.pyplot as plt

for i in range(3):
    plt.plot([1,2,3],[3-i, i/3., i], marker="o",label="label {}".format(i))

plt.legend(markerfirst=False)
plt.show()

enter image description here

Upvotes: 2

Related Questions