matplotlib 图例标记仅一次 [英] matplotlib Legend Markers Only Once

查看:34
本文介绍了matplotlib 图例标记仅一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常在 matplotlib 图上绘制一个点:

I often plot a point on a matplotlib plot with:

x = 10
y = 100
plot(x, y, "k*", label="Global Optimum")
legend()

然而,这会导致图例在图例中放置了两次星星,使其看起来像:

However, this causes the legend to put a star in the legend twice, such that it looks like:

* * Global Optimum

当我真的希望它看起来像时:

when I really want it to look like:

 *  Global Optimum

我该怎么做?

推荐答案

这应该有效:

legend(numpoints=1)

顺便说一句,如果您添加该行

BTW, if you add the line

legend.numpoints     : 1      # the number of points in the legend line

到您的 matplotlibrc 文件,然后这将是新的默认值.

to your matplotlibrc file, then this will be the new default.

[另见散点,取决于你的情节.]

[See also scatterpoints, depending on your plot.]

API:API 文档链接

这篇关于matplotlib 图例标记仅一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆