matplotlib: put legend symbols on the right of the labels

自古美人都是妖i 提交于 2019-11-29 14:08:11

问题


It's a simple thing but I've searched for quite a while without success: I want to customise a figure legend by reversing the horizontal order of the symbols and labels.

In Gnuplot, this is simply achieved by set key reverse. Example: change x data1 to data1 x. In matplotlib, there seems to be no user-friendly solution. Thus, I thought about changing a kind of handle anchor or just shifting the handle's position, but couldn't find any point to start with.


回答1:


The requested feature is already there, as the keyword markerfirst of the legend command.

    plt.plot([1,2],[3,4], label='labeltext')
    plt.legend(markerfirst=False)
    plt.show()

If you want to make it your default behaviour, you can change the value of legend.markerfirst in rcParams, see customizing matplotlib.



来源:https://stackoverflow.com/questions/24867363/matplotlib-put-legend-symbols-on-the-right-of-the-labels

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!