python - 图例中的额外标记

标签 python numpy matplotlib legend

我不明白为什么我的图例显示每个标记中的三个(我只想要一个)。

谷歌/stackoverflow 引导我找到 numpoints = 1 ,但是我的问题仍然存在。有什么想法或建议吗?

代码:

fig, ax = plt.subplots(figsize=(14,7))
fig.patch.set_facecolor('white')

.....

markers = ["o", "s", "d", "v"]
for i in range(4):
    plt.scatter([j for j in range(1,7)],
                ygroup[i],
                s = 38,
                c = colours[i],
                marker = markers[i],
                edgecolors='none',
                label = instloop[i])

ax.legend(loc = 'best', numpoints = 1)
show()

图片:

enter image description here

最佳答案

散点图有一个特殊的关键字参数 - 您希望将 scatterpoints=1 传递给 ax.legend()

关于python - 图例中的额外标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23704026/

相关文章:

python - 在 matplotlib 中使用带线图的颜色图

python - 将 Python 从 2.6 更新到 2.7 时,更新 Python 包的正确方法是什么?

python - numpy:二维矩阵的行乘积

python - 查找满足条件的 numpy 数组元素

python - 如何在 pyplot (matplotlib) 中的同一个图上添加两个颜色条?

python - Jupyter笔记本: interactive plot with widgets

python - 如何迭代一系列排列?

python - 如何计算使用keras训练的语言模型的困惑度?

python - 如何禁止将软件包添加到 Pipenv.lock 并由 Pipenv 安装?

python - numpy 数组子集的元素平方