我经常绘制一个点上matplotlib阴谋有:matplotlib传奇标记只有一次
x = 10
y = 100
plot(x, y, "k*", label="Global Optimum")
legend()
然而,这将导致传说把传说中的明星的两倍,使得它看起来像:
* * Global Optimum
当我真的希望它看起来像:
* Global Optimum
我该怎么办呢?
我经常绘制一个点上matplotlib阴谋有:matplotlib传奇标记只有一次
x = 10
y = 100
plot(x, y, "k*", label="Global Optimum")
legend()
然而,这将导致传说把传说中的明星的两倍,使得它看起来像:
* * Global Optimum
当我真的希望它看起来像:
* Global Optimum
我该怎么办呢?
这应该工作:
legend(numpoints=1)
顺便说一句,如果添加行
legend.numpoints : 1 # the number of points in the legend line
您matplotlibrc文件,那么这将是新的默认。
[见scatterpoints,这取决于你的情节。]
API:Link to API docs
谢谢。我今天也遇到了这个。为什么这不是默认? – saltycrane 2011-05-27 06:45:38
你可以添加一个链接到api吗? http://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes.legend我可以在自己编辑它,但这似乎粗鲁。 – tacaswell 2013-09-23 18:20:22
忽略我的删除评论为什么默认是它是什么,他们是错的。 – tacaswell 2013-09-23 18:28:10
我喜欢动态地改变每个python脚本我matplotlib RC参数。为了实现这个目标,我简单地在我的python文件的开头使用类似的东西。
from pylab import *
rcParams['legend.numpoints'] = 1
这将适用于从我的python文件生成的所有图。
编辑:对于那些谁不喜欢导入pylab,长的回答是
import matplotlib as mpl
mpl.rcParams['legend.numpoints'] = 1
我希望我能这个问题,多次给予好评。我讨厌默认的'numpoints = 2'大会,看到有人已经花时间询问并得到答案,我感到宽慰。 – 2011-08-14 15:33:18
注意:散点图的选项是'scatterpoints = 1' – 2014-03-06 16:05:33