【问题标题】:Matplotlib legend numpoints don't workMatplotlib 图例 numpoints 不起作用
【发布时间】:2016-01-18 22:48:34
【问题描述】:

我有这样一段代码:

import matplotlib as mpl
from matplotlib import pyplot as plt

mpl.rcParams['legend.numpoints'] = 1
plt.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=3,
           ncol=5, mode="expand", numpoints=1, borderaxespad=0.)

但它不起作用。点数仍然是3。 有任何想法吗?

【问题讨论】:

    标签: python matplotlib legend


    【解决方案1】:

    图中带有 3 个点的图例句柄来自散点图。您可以使用scatterpoints kwarg 控制它们。

    numpoints 用于使用plt.plot 创建的对象,而不是plt.scatter

    plt.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=3,
               ncol=5, mode="expand", numpoints=1, borderaxespad=0., 
               scatterpoints=1)
    

    或者

    mpl.rcParams['legend.scatterpoints'] = 1
    

    【讨论】:

      猜你喜欢
      • 2012-08-12
      • 2021-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-26
      • 1970-01-01
      • 2023-03-18
      相关资源
      最近更新 更多