gpt4 book ai didi

python - Matplotlib 图例数字点不起作用

转载 作者:行者123 更新时间:2023-11-28 22:39:20 25 4
gpt4 key购买 nike

我有这样一段代码:

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。有任何想法吗? enter image description here

最佳答案

你图中的图例句柄有 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

关于python - Matplotlib 图例数字点不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34865510/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com