Matplotlib

Matplotlib Colormaps 0

Matplotlib Colormaps

Program 1 import matplotlib.pyplot as plt import numpy as np x = np.array([5,7,8,7,2,17,2,9,4,11,12,9,6]) y = np.array([99,86,87,88,111,86,103,87,94,78,77,85,86]) colors = np.array([10,20,25,35,50,60,75,80,90,100,110,120,130]) plt.scatter(x,y,cmap=’BuPu’,c=colors) plt.colorbar() plt.xlabel(“Car Age”) plt.ylabel(“Milage”) plt.legend() plt.show() #x1 = np.array([2,2,8,1,15,8,12,9,7,3,11,4,7,14,12]) # y1 = np.array([100,105,84,105,90,99,90,95,94,100,79,112,91,80,85]) #...

Matplotlib Scatter Graph 0

Matplotlib Scatter Graph

Program 1 import matplotlib.pyplot as plt import numpy as np x = np.array([5,7,8,7,2,17,2,9,4,11,12,9,6]) y = np.array([99,86,87,88,111,86,103,87,94,78,77,85,86]) x1 = np.array([2,2,8,1,15,8,12,9,7,3,11,4,7,14,12]) y1 = np.array([100,105,84,105,90,99,90,95,94,100,79,112,91,80,85]) x2 = np.array([4,3,8,1,10,9,12,7,8,5,10,6,7,12,14]) y2 = np.array([104,100,78,102,94,98,92,97,92,110,89,112,94,82,89]) plt.scatter(x, y) plt.scatter(x1, y1) plt.scatter(x2, y2)...

xticks(), yticks(), xlim(), ylim() Methods in Matplotlib 0

xticks(), yticks(), xlim(), ylim() Methods in Matplotlib

Program 1 import matplotlib.pyplot as mat x=[0,10,20,30,40,50] y=[0,100,200,300,400,500] mat.plot(x,y) c={‘family’:’Times New Roman’,’size’:20,’color’:’r’} fc1={‘family’:’Times New Roman’,’size’:25,’color’:’g’} mat.xlabel(“Product”,fontdict=c) mat.ylabel(“Price”,fontdict=fc1) mat.title(“Data Flair”,fontdict=fc1) mat.xticks(x,[‘A’,’B’,’C’,’D’,’E’,’F’]) mat.yticks(y,[’50-60′,’10-20′,’20-30′,’30-40′,’40-50′,’50-60′]) # mat.xlim([10,100]) # mat.ylim([100,500]) mat.show()    

Matplotlib Subplot 0

Matplotlib Subplot

Program 1 import matplotlib.pyplot as mat x=[0,1,2,3,4,5] y=[0,1,4,9,16,25] x1=[10,20,30,40,50] y1=[10,30,20,50,40] x2=[100,200,300,400,500] y3=[100,400,300,500,200] mat.subplot(3,1,1) mat.plot(x,y,marker=”o”,mec=’k’,mfc=’r’,ms=10,ls=”solid”,lw=5,c=’b’,label=’Product1 ‘) mat.plot(y1,x1,marker=”o”,mec=’r’,mfc=’k’,ms=10,ls=”solid”,lw=5,c=’g’,label=’Product 2′) mat.xlabel(“X-Product”) mat.xlabel(“Y Product”) mat.title(“Product”) mat.legend() mat.subplot(3,1,2) mat.plot(x1,y1,marker=”o”,mec=’y’,mfc=’k’,ms=10,ls=”solid”,lw=5,c=’r’,label=’Sales’) mat.xlabel(“X-Sales”) mat.xlabel(“Y-Sales”) mat.title(“Sales”) mat.legend() mat.subplot(3,1,3) mat.plot(x1,y1,marker=”o”,mec=’y’,mfc=’k’,ms=10,ls=”solid”,lw=5,c=’r’,label=’Company’) mat.xlabel(“X-Company”) mat.xlabel(“Y-Company”) mat.title(“Company”) mat.legend()...

Matplotlib Legends 0

Matplotlib Legends

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)...

Matplotlib Line Style and Markers 0

Matplotlib Line Style and Markers

Program 1 import matplotlib.pyplot as plt x=[10,20,30,40,50] y=[10,50,40,30,20] #plt.plot(x,y,ls=”solid”,lw=3,c=’k’) plt.plot(x,y,marker=”o”,mec=’k’,mfc=’r’,ms=10,ls=”solid”,lw=5,c=’b’) plt.title(“Student Info”) plt.xlabel(“X-Axis”) plt.ylabel(“Y-Axis”) plt.show() # o-circle # d-Dimond # p-Pentagon # h-Hexagone # * -star # + Plus # _ Horigantal lines #...

How to Change Font of Title in Matplotlib 0

How to Change Font of Title in Matplotlib

Program 1 import matplotlib.pyplot as mat x=[0,1,2,3,4,5] y=[i**2 for i in x] mat.plot(x,y,marker=’.’,mfc=’y’,mec=’k’,ms=10,ls=”dotted”,lw=2,c=’r’) 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()  

Matplotlib Pie Charts 0

Matplotlib Pie Charts

Program 1 import matplotlib.pyplot as mat st_result=[“Ist Division”,”II Division”,”III Division”,”Supp”,”Fail”] #st_result=[“BJP”,”Congress”,”AAP”,”ABCD”,”XYZ”] st_value=[750,230,170,190,80] mat.figure(figsize=(12,10)) mat.pie(st_value,labels=st_result,startangle=0,explode=[0.1,0.1,0.1,0.1,0.1],autopct=”%2.1f%%”,shadow=True,colors=[‘green’,’blue’,’yellow’,’white’,’red’]) mat.legend( loc=”upper right”) mat.title(“Data Flair Student Result”) mat.show()  

Multiple Bar Charts in Matplotlib 0

Multiple Bar Charts in Matplotlib

Program 1 import matplotlib.pyplot as mat years=[2021,2022,2023,2024,2025] frooti=[100,350,500,400,700] limca=[200,400,200,300,500] pepsi=[600,200,400,700,500] milk=[700,500,300,500,400] wd=0.2 f_bar=[0,1,2,3,4] l_bar=[i+wd for i in f_bar] p_bar=[i+wd for i in l_bar] m_bar=[i+wd for i in p_bar] # print(f_bar) # print(l_bar) fc={‘family’:’Times New...

Matplotlib Histograms 0

Matplotlib Histograms

Program 1 import matplotlib.pyplot as mat #A histogram is a graph showing frequency distributions. #It is a graph showing the number of observations within each given interval. stud_result=[22,25,35,42,45,50,54,67,66,64,70,72,75,79,82,87,89,94,96,98,99] per_range=[0,30,50,60,70,80,90,100] #mycolors=[‘red’,’green’,’blue’,’black’,’yellow’,’red’,’green’,’blue’] mat.hist(stud_result,per_range,rwidth=0.5,histtype=”bar”,facecolor=’b’) mat.xticks(per_range) fc={‘family’:’Times New...