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

查看:78
本文介绍了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天全站免登陆