我经常使用以下代码在matplotlib的图表上画点:
x = 10
y = 100
plot(x, y, "k*", label="Global Optimum")
legend()
然而,这会导致图例在图例中两次放置一个星号,使其看起来像:
* * Global Optimum
当我真的想要它看起来像这样:
* Global Optimum
我怎么做这个?
我经常使用以下代码在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: 链接至API文档
from pylab import *
rcParams['legend.numpoints'] = 1
import matplotlib as mpl
mpl.rcParams['legend.numpoints'] = 1
scatterpoints=1
是用于散点图的。 - Marcos Alex