我经常在 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 文件,那么这将是新的默认值。
[另请参见散点,具体取决于您的情节。]
API:Link to API docs
关于python - matplotlib 图例标记仅一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6146778/