matplotlib - questions on multiple plots and multiple legend on python -


i have following code, 1 me fix it? have multiple legends on python numpy / matlab graph.

 import numpy np     import matplotlib.pyplot plt     fig = plt.figure(1)     x0 = np.array([[1,2,2,3]])     x1 = np.array([[2,2,4,3]])     y0 = np.array([[1,6,2,7]])     y0 = np.array([[4,2,2,5]])     p1= plt.scatter(x0,x1,color='blue',s=3)     p2= plt.scatter(y0,y0,color='red',s=3)     leg = plt.legend((p1,p2),('class0','class1'),fontsize=8)     plt.show() 

i want following figure on fig , have own legend

    plt.hold(true)     z0 = np.array([[11,16,13,17]])     z1 = np.array([[13,16,12,17]])     p3 = plt.scatter(z0,z1,color='k')     plt.show() 

how should add legend p3?

here have 3 scatterplots on same figure 1 legend in top-right , other on bottom-right.

we can both legends show adding first legend axes described in matplotlib legend guide:

import numpy np import matplotlib.pyplot plt  fig = plt.figure(1) x0 = np.array([[1,2,2,3]]) x1 = np.array([[2,2,4,3]]) y0 = np.array([[1,6,2,7]]) y0 = np.array([[4,2,2,5]]) p1= plt.scatter(x0,x1,color='blue',s=50, label='class0') p2= plt.scatter(y0,y0,color='red',s=50, label='class1') z0 = np.array([[11,16,13,17]]) z1 = np.array([[13,16,12,17]]) p3 = plt.scatter(z0,z1,color='k', s=75, label='class3')  leg = plt.legend(handles=[p1, p2], fontsize=8, loc=1) ax = plt.gca().add_artist(leg) plt.legend(handles=[p3], fontsize=8, loc=4) plt.show() 

enter image description here


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -