Python 在matplotlib图例中设置numpoints无效

Python 在matplotlib图例中设置numpoints无效,python,matplotlib,legend,Python,Matplotlib,Legend,我试图通过以下建议在绘图图例上创建一个数据点,但它似乎不起作用: from pylab import scatter import pylab import matplotlib.pyplot as plt fig = plt.figure() ax = plt.gca() ax.scatter(1,2,c = 'blue', marker = 'x') ax.scatter(2,3, c= 'red', marker = 'o') ax.legend(('1','2'), loc = 2,

我试图通过以下建议在绘图图例上创建一个数据点,但它似乎不起作用:

from pylab import scatter
import pylab
import matplotlib.pyplot as plt

fig = plt.figure()
ax = plt.gca()
ax.scatter(1,2,c = 'blue', marker = 'x')
ax.scatter(2,3, c= 'red', marker = 'o')
ax.legend(('1','2'), loc = 2, numpoints = 1)
plt.show()

我在这里做什么蠢事吗?一些补充资料:

In [147]:  import matplotlib 
           print matplotlib.__version__

Out [147]: 1.1.1rc   
对于散点图,请使用以下参数:

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.scatter(1, 2, c='blue', marker='x')
ax.scatter(2, 3, c='red', marker='o')
ax.legend(('1', '2'), loc=2, scatterpoints=1)
plt.show()

回答得很好,我永远也猜不到这一点。使用两个不同的参数来做几乎相同的事情似乎毫无意义。轴可以同时包含直线图和散点图,因此有两个参数,
散点和
numpoints
,允许您独立控制这些图例项的外观。