matplotlib 中修改图例中的标记符显示数量

默认效果:

import matplotlib.pyplot as plt

%matplotlib inline
x1, y1 = range(1,5), range(2, 6)
x2, y2 = range(5, 9), range(3, 7)

plt.figure(figsize=(8, 5))
plt.scatter(x1, y1, marker='x', label='I')
plt.scatter(x2, y2, label='II')
plt.legend()

 

 

修改 legend()  中的 scatterpoints 参数:

import matplotlib.pyplot as plt

%matplotlib inline
x1, y1 = range(1,5), range(2, 6)
x2, y2 = range(5, 9), range(3, 7)

plt.figure(figsize=(8, 5))
plt.scatter(x1, y1, marker='x', label='I')
plt.scatter(x2, y2, label='II')
plt.legend(scatterpoints=2)

效果如下:

 

 

 

posted @ 2020-01-05 21:45  赏尔  阅读(855)  评论(0编辑  收藏  举报