Matplotlib: Group different scatter markers under the same legend

℡╲_俬逩灬. 提交于 2019-12-02 01:11:50

Found it!

import matplotlib.pyplot as plt
from matplotlib.legend_handler import HandlerTuple
import numpy as np
group1 = np.array([[1,4,6],[3,2,5]])
group2 = np.array([[1,5,9],[2,2,5]])
group3 = np.array([[1,4,2],[11,2,7]])
a, =plt.plot(group1[0,:],group1[1,:], 'ro', marker='^')
b, =plt.plot(group2[0,:],group2[1,:], 'bo', marker='o')
c, =plt.plot(group3[0,:],group3[1,:], 'go', marker='s')
plt.legend([(a,b,c)], ['goupdata'], numpoints=1, handler_map={tuple: HandlerTuple(ndivide=None)})
plt.show()

Thanks very much to anyone that at least tried to help!

Update: Something that i found useful; If you want to add more than one entries:

plt.legend([(a,b),(c)], ['goupdata1', 'groupdata2'], numpoints=1, handler_map={tuple: HandlerTuple(ndivide=None)})
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!