Site icon DataFlair

Matplotlib Program for Legend Function

Machine Learning courses with 110+ Real-time projects Start Now!!

Program 1

import matplotlib.pyplot as mat
x=[0,1,2,3,4,5]
y=[0,1,4,9,16,25]
y1=[0,10,20,30,40,50]
y2=[0,20,10,40,30,50]
#mat.plot(x,y,x,y1)
# mat.legend(['Sales','Product'])
mat.plot(x,y,label="Product",marker=".",mfc='r',mec='k')
mat.plot(x,y1,label="Sales",marker="*",mfc='y',mec='k')
mat.plot(x,y2,label="Company",marker=".",mfc='c',mec='k')
mat.legend(loc=2,facecolor='cyan',edgecolor='red',framealpha=0.5,shadow=True,fancybox=True)
mat.show()

 

Exit mobile version