GRAPHS USING MATPLOTLIB
GRAPHS USING MATPLOTLIB
#there are two parameters for specifying points in the diagram i.e. x-axis and y-axis.
#here in the diagram the line appears bcz it is the by default function.
import matplotlib.pyplot as plt #now the pyplot package can be refered as plt
*BAR CHART*
#MORE EXAMPLES
Cars=['Audi','BMW','Ford','Tesla','Jaguar','Mercedes']
Sold=[23,17,35,29,12,41]
fig=plt.figure(figsize=(4,4))
plt.pie(Sold,labels=Cars,colors=['lightblue','pink','white','yellow','lightgreen','orange'],wedgeprops={'linewidth'
explode=(0.1,0.1,0.1,0.1,0.1,0.1),textprops={'fontfamily':'serif','fontsize':12})
plt.show()
*SCATTER PLOTS*
x=[2,3,4,5,6]
y=[4,6,8,10,12]
y2=[-2,-3,-4,-5,-6]
plt.scatter(x,y,color='orange',marker="*",label='data1')#plt.scatter is used to create scatter plots.
plt.scatter(x,y2,color='blue',marker="o",label='data2')
plt.legend()#plt.legend gives meaning to a visualization, assign meaning to the various plot elements.
plt.xlabel("x")#plt.xlabel is used to add a label to the x-axis of a plot
plt.ylabel("y")#plt.ylabel is used to add a label to the y-axis of a plot
plt.title("Numbers")#plt.title is used to add a title to the charts/plots
plt.show()#plt.show is used to display the created charts/plots
*GRAPH OF SIN X*
x=np.linspace(0,2*np.pi,100)#linspace() allows you to specify the total number of points you want in the array
y=np.sin(x)#np.sin(x) helps to find sine value of the angle in degree and radian
plt.plot(x,y,label='sinx',color='red')#plt.plot is used for creating line plots
plt.xlabel('x')#plt.xlabel is used to add a label to the x-axis of the plot
plt.ylabel('y')#plt.ylabel is used to add a label to the y-axis of the plot
plt.title('graph of sinx')#plt.title is used to give the title of the plot
plt.legend ()#plt.legend gives meaning to a visualization, assign meaning to the various plot elements
plt.show()#plt.show is used t display the created plots/charts
*GRAPH OF COS X*
x=np.linspace(0,2*np.pi,100)#linspace() allows you to specify the total number of points you want in the array
y=np.cos(x)#np.cos(x) helps to compute the cosine of an angle x given in radians.
plt.plot(x,y,label='cosx',color='blue')#plt.plot is used for creating line plots
#label is used for labelling the graph.
#plt.xlabel is used to add a label to the x-axis of the plot
#plt.ylabel is used to add a label to the y-axis of the plot
#plt.title is used to give the title of the plot
#plt.legend gives meaning to a visualization, assign meaning to the various plot elements
#plt.show is used t display the created plots/charts
plt.xlabel('x')
plt.ylabel('y')
plt.title('graph of cosx')
plt.legend()
plt.show()
*GRAPH OF X*X
x=np.linspace(0,20,100)#linspace() allows you to specify the total number of points you want in the array
y=x*x
plt.plot(x,y,label='x*x',color='green')
plt.xlabel('x')
plt.ylabel('y')
plt.title('graph of x*x')
plt.legend()
plt.show()
#plt.plot is used for creating line plots
#label is used for labelling the graph.
#plt.xlabel is used to add a label to the x-axis of the plot
#plt.ylabel is used to add a label to the y-axis of the plot
#plt.title is used to give the title of the plot
#plt.legend gives meaning to a visualization, assign meaning to the various plot elements
#plt.show is used t display the created plots/charts
*GRAPH OF TAN X*
x=np.linspace(0,2*np.pi,100)#linspace() allows you to specify the total number of points you want in the array
y=np.tan(x)#np.tan(x) helps user to calculate trigonometric tangent for all x(being the array elements)
plt.plot(x,y,label='tanx',color='orange')
plt.xlabel('x')
plt.ylabel('y')
plt.title('graph of tanx')
plt.legend()
plt.show()
#plt.plot is used for creating line plots
#label is used for labelling the graph.
#plt.xlabel is used to add a label to the x-axis of the plot
#plt.ylabel is used to add a label to the y-axis of the plot
#plt.title is used to give the title of the plot
#plt.legend gives meaning to a visualization, assign meaning to the various plot elements
#plt.show is used t display the created plots/charts
# Sample data
data = [8, 16, 12, 19, 22, 17, 13, 14, 11, 20]
# Create figure
plt.figure(figsize=(8, 5))
# Importing libraries
import matplotlib.pyplot as plt
# Sample data
data_dict = {
'Group A': [23, 45, 56, 67, 34, 89, 45],
'Group B': [34, 56, 78, 12, 45, 67, 89],
'Group C': [13, 24, 35, 46, 57, 68, 79]
}