matplotlib:将图例符号放在标签的右侧 [英] matplotlib: put legend symbols on the right of the labels
问题描述
这很简单,但是我已经搜索了很长时间没有成功:我想通过反转符号和标签的水平顺序来自定义图例.
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.
在Gnuplot中,只需通过反向设置键即可实现.示例:将x data1
更改为data1 x
.在matplotlib中,似乎没有用户友好的解决方案.因此,我考虑过更改手柄的锚点或只是移动手柄的位置,但找不到任何起点.
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.
推荐答案
所请求的功能已经存在,作为legend
命令的关键字markerfirst
.
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()
如果要使其成为默认行为,则可以在rcParams
中更改legend.markerfirst
的值,请参见
If you want to make it your default behaviour, you can change the value of legend.markerfirst
in rcParams
, see customizing matplotlib.
这篇关于matplotlib:将图例符号放在标签的右侧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!