Legends with text to the right of line styles

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

That is, I need a legend that looks like this:

Legend with text

thank

+3


source to share


1 answer


As you can see from the legend

documentation
, there is an argument markerfirst

that can be set to False so that the markers are displayed last.

plt.legend(markerfirst=False)

      

Complete 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

+2


source







All Articles