Matplotlib Legends

Machine Learning courses with 100+ 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,14,26,38,42,58]
#mat.plot(x,y,marker='.',mfc='y',mec='k',ms=10,ls="solid",lw=2,c='r')

#mat.plot(x,y,x,y1)
#mat.legend(['Sales','Product'])

mat.plot(x,y,marker='.',mfc='y',mec='k',ms=10,ls="solid",lw=2,c='r',label='Sales')
mat.plot(x,y1,marker='.',mfc='r',mec='k',ms=10,ls="solid",lw=2,c='b',label='Product')
mat.plot(x,y2,marker='.',mfc='g',mec='k',ms=10,ls="solid",lw=2,c='k',label='Company')
#mat.legend(loc=10)
mat.legend(loc='upper left',facecolor='yellow',edgecolor='red',framealpha=0.5,shadow=True,fancybox=True)
#mat.legend(loc='upper right')
#mat.legend(loc='lower left')
#mat.legend(loc='lower right')

fc={'family':'Times New Roman','size':20,'color':'r'}
fc1={'family':'Times New Roman','size':25,'color':'g'}
fc2={'family':'Verdana','size':30,'color':'b'}
mat.xlabel("X-Axis",fontdict=fc)
mat.ylabel("Y-Axis",fontdict=fc)
mat.title("Line Chart",fontdict=fc2)
mat.show()

 

If you are Happy with DataFlair, do not forget to make us happy with your positive feedback on Google

courses

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *