2D & 3D Graphs
2D & 3D Graphs
import numpy as np
# Trigonometric function #
import numpy as np
x=np.arange(0,2*(np.pi),0.01) # np.arange() : used to plot points in the specified interval with specified distance #
# Sine function #
import numpy as np
x=np.arange(0,(np.pi/2),0.1) # np.arange() : used to plot points in the specified interval with specified
distance #
plt.show()
# Inverse trigonometric functions #
import numpy as np
x=np.arange(-1,1,0.1) # np.arange() : used to plot points in the specified interval with specified distance #
plt.show()
# Algebraic function #
import numpy as np
# Exponential function #
import numpy as np
import numpy as np
y=np.sin(x)-np.exp(x)+3*x**2+np.log10(x)
# Line Graph #
x1=[1,2,3]
y1=[3,6,2]
x2=[1,2,3]
y2=[7,2,5]
plt.xlabel("x-axis")
plt.ylabel("y-axis")
plt.legend()
plt.show()
# Bar Graph #
left=[1,2,3,4,5]
height = [5,24,45,32,15]
tick_label=['Pune','Mumbai','Nagpur','Nasik','Satara']
plt.xlabel('cities')
plt.title('covid-19 data')
plt.show()
# Histogram #
ages=[2,5,70,40,30,45,50,45,43,40,44,60,7,13,57,18,90,77,32,21,20,40,45,32,38]
range=(0,100)
plt.hist(ages,bins,range,color='blue',histtype='bar',rwidth=0.9)
plt.xlabel('ages')
plt.ylabel('Number of people')
plt.title('Histogram plot')
plt.show()
# Pie Chart #
left=[1,2,3,4,5]
height=[5,24,45,32,15]
tick_label= ['Pune','Mumbai','Nagpur','Nasik','Satara']
plt.pie(height,lab els=tick_label)
plt.show()
# Scatter plot #
girls_scores=[81,90,70,89,100,80,90,100,80,54]
boys_scores=[30,29,49,48,100,48,34,45,20,30]
grades_range=[10,20,30,40,50,60,70,80,90,100]
fig=plt.figure()
ax.scatter(grades_range,girls_scores,color='red')
ax.scatter(grades_range,boys_scores,color='blue')
ax.set_xlabel('grades range')
ax.set_ylabel('grades scored')
ax.set_title('scatter plot')
plt.show()
legend()
show()
# 3- Dimensional frame #
import numpy as np
fig=plt.figure()
ax=plt.axes(projection='3d')
import numpy as np
fig=plt.figure()
ax=plt.axes(projection='3d')
zvalue=np.linspace(0,15,10)
xvalue=np.sin(zvalue)
yvalue=np.cos(zvalue)
ax.plot3D(xvalue,yvalue,zvalue,'red')
import numpy as np
fig=plt.figure()
ax=plt.axes(projection='3d')
zvalue=np.linspace(0,15,50)
xvalue=np.sin(zvalue)
yvalue=np.cos(zvalue)
ax.scatter3D(xvalue,yvalue,zvalue,'red')
# 3D graph of exp(-x**2-y**2) #
import numpy as np
fig=plt.figure()
def f(x,y):
return np.exp(-x**2-y**2)
x=np.linspace(-2,2,100)
y=np.linspace(-2,2,100)
X,Y=np.meshgrid(x,y)
Z=f(X,Y)
ax=plt.axes(projection='3d')
ax.contour3D(X,Y,Z,50,cmap='RdBu')
ax.set_xlabel('x')
ax.set_xlabel('y')
ax.set_xlabel('z')
# Wireframe#
import numpy as np
fig=plt.figure()
def f(x,y):
return np.exp(-x**2-y**2)
x=np.linspace(-2,2,100)
y=np.linspace(-2,2,100)
X,Y=np.meshgrid(x,y)
Z=f(X,Y)
ax=plt.axes(projection='3d')
ax.plot_wireframe(X,Y,Z,50,color='red')
ax.set_xlabel('x')
ax.set_xlabel('y')
ax.set_xlabel('z')
# sin(x**2+y**2) #
import numpy as np
fig=plt.figure()
def f(x,y):
return np.sin(x**2+y**2)
x=np.linspace(-2,2,100)
y=np.linspace(-2,2,100)
X,Y=np.meshgrid(x,y)
Z=f(X,Y)
ax=plt.axes(projection='3d')
ax.contour3D(X,Y,Z,50,cmap='RdBu')
ax.set_xlabel('x')
ax.set_xlabel('y')
ax.set_xlabel('z')
# exp(-x**2) #
import numpy as np
fig=plt.figure()
def f(x,y):
return np.exp(-x**2)
x=np.linspace(-2,2,100)
y=np.linspace(-2,2,100)
X,Y=np.meshgrid(x,y)
Z=f(X,Y)
ax=plt.axes(projection='3d')
ax.contour3D(X,Y,Z,50,cmap='RdBu')
ax.set_xlabel('x')
ax.set_xlabel('y')
ax.set_xlabel('z')
# sinx+ cosy #
import numpy as np
fig=plt.figure()
def f(x,y):
return np.sin(x)+np.cos(y)
x=np.linspace(-10,10,100)
y=np.linspace(-10,10,100)
X,Y=np.meshgrid(x,y)
Z=f(X,Y)
ax=plt.axes(projection='3d')
ax.contour3D(X,Y,Z,50,cmap='RdBu')
ax.set_xlabel('x')
ax.set_xlabel('y')
ax.set_xlabel('z')
# x**2+y**2 #
import numpy as np
fig=plt.figure()
def f(x,y):
return (x**2+y**2)
x=np.linspace(-10,10,100)
y=np.linspace(-10,10,100)
X,Y=np.meshgrid(x,y)
Z=f(X,Y)
ax=plt.axes(projection='3d')
ax.contour3D(X,Y,Z,50,cmap='RdBu')
ax.set_xlabel('x')
ax.set_xlabel('y')
ax.set_xlabel('z')
# sin(x**2+y**2) #
import numpy as np
fig=plt.figure()
def f(x,y):
return np.sin(x**2+y**2)
x=np.linspace(-10,10,100)
y=np.linspace(-10,10,100)
X,Y=np.meshgrid(x,y)
Z=f(X,Y)
ax=plt.axes(projection='3d')
ax.contour3D(X,Y,Z,50,cmap='RdBu')
ax.set_xlabel('x')
ax.set_xlabel('y')
ax.set_xlabel('z')