Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

1/20/24, 12:25 PM Surface Plots- Jan 6th - Jupyter Notebook

SURFACE PLOTS
1 Date: 06/01/24 and LAB-4

1 AIM: In this lab, we shall explore the mpl_toolkits module and import the mplot3d
function and use meshgrid(), axes() and projection() to plot different surface
plots.

In [2]:  1 from mpl_toolkits.mplot3d import Axes3D


2 from matplotlib.pyplot import *
3 from numpy import *

In [4]:  1 x,z= meshgrid(range(10), range(10))


2 y=0
3 ax=axes(projection='3d')
4 ax.plot_surface(x,y,z)
5 title("Plane")
6 ax.set_xlabel("$X$")
7 ax.set_ylabel("$Y$")
8 ax.set_zlabel("$Z$")
9 show()

localhost:8888/notebooks/Python SEM4/Surface Plots- Jan 6th.ipynb# 1/6


1/20/24, 12:25 PM Surface Plots- Jan 6th - Jupyter Notebook

In [5]:  1 y,z= meshgrid(range(10), range(10))


2 x=2
3 ax=axes(projection='3d')
4 ax.plot_surface(x,y,z)
5 title("Plane")
6 ax.set_xlabel("$X$")
7 ax.set_ylabel("$Y$")
8 ax.set_zlabel("$Z$")
9 show()

In [11]:  1 ax= axes(projection= '3d')


2 u= linspace(0, 2*pi, 100)
3 v= linspace(0,pi, 100)
4 x= 10*outer(cos(u), sin(v))
5 y= 10*outer(sin(u), sin(v))
6 z= 10*outer(ones(size(v)), cos(v))
7 ax.plot_surface(x,y,z,color='pink')
8 show()
9 ​
10 ​

localhost:8888/notebooks/Python SEM4/Surface Plots- Jan 6th.ipynb# 2/6


1/20/24, 12:25 PM Surface Plots- Jan 6th - Jupyter Notebook

In [12]:  1 ax= axes(projection= '3d')


2 u= linspace(0, 2*pi, 100)
3 v= linspace(0,8 , 100)
4 x= 10*outer(ones(size(u)), cos(u))
5 y= 10*outer(ones(size(u)), sin(u))
6 z= 10*outer(v,ones(size(v)))
7 ax.plot_surface(x,y,z,color='teal')
8 show()

In [16]:  1 ax= axes(projection= '3d')


2 u= linspace(0,2*pi, 100)
3 v= linspace(-2,2, 100)
4 x= 10*outer(v, cos(u))
5 y= 10*outer(v, sin(u))
6 z= 10*outer(v,ones(size(u)))
7 ax.plot_surface(x,y,z,color='teal')
8 show()

localhost:8888/notebooks/Python SEM4/Surface Plots- Jan 6th.ipynb# 3/6


1/20/24, 12:25 PM Surface Plots- Jan 6th - Jupyter Notebook

In [15]:  1 ax=Axes3D(figure())
2 x= arange(-3*pi, 3*pi, 0.1)
3 y= arange(-3*pi, 3*pi, 0.1)
4 xx,yy= meshgrid(x,y)
5 z= sin(xx)*sin(yy)
6 ax.plot_surface(xx, yy, z, cmap=cm.jet)
7 show()

C:\Users\liona\AppData\Local\Temp\ipykernel_36392\1212097329.py:1: MatplotlibDepreca
tionWarning: Axes3D(fig) adding itself to the figure is deprecated since 3.4. Pass t
he keyword argument auto_add_to_figure=False and use fig.add_axes(ax) to suppress th
is warning. The default value of auto_add_to_figure will change to False in mpl3.5 a
nd True values will no longer work in 3.6. This is consistent with other Axes class
es.
ax=Axes3D(figure())

localhost:8888/notebooks/Python SEM4/Surface Plots- Jan 6th.ipynb# 4/6


1/20/24, 12:25 PM Surface Plots- Jan 6th - Jupyter Notebook

In [22]:  1 ax=Axes3D(figure())
2 x= arange(-3*pi, 3*pi, 0.1)
3 y= arange(-3*pi, 3*pi, 0.1)
4 xx,yy= meshgrid(x,y)
5 z= xx+yy
6 ax.plot_surface(xx, yy, z, cmap=cm.Spectral)
7 show()

C:\Users\liona\AppData\Local\Temp\ipykernel_36392\1025354389.py:1: MatplotlibDepreca
tionWarning: Axes3D(fig) adding itself to the figure is deprecated since 3.4. Pass t
he keyword argument auto_add_to_figure=False and use fig.add_axes(ax) to suppress th
is warning. The default value of auto_add_to_figure will change to False in mpl3.5 a
nd True values will no longer work in 3.6. This is consistent with other Axes class
es.
ax=Axes3D(figure())

Vectors
In [24]:  1 ax= axes(projection= "3d")
2 x,y,z =meshgrid( arange(-0.8, 1, 0.2),
3 arange(-0.8, 1, 0.2),
4 arange(-0.8, 1, 0.8))
5 u= sin(pi*x)*cos(pi*y)*cos(pi*z) #vectorsof the form ui + vj + wz
6 v= cos(pi*x)*sin(pi*y)*cos(pi*z)
7 w=(sqrt(2.0/3.0)*cos(pi*x)*cos(pi*y)*sin(pi*z))
8 ax.quiver(x,y,z,u,v,w, length= 0.3) #x, y, z defines the arrow location
9 show()

𝑢 = 𝑥/𝑥 ∗ ∗2 + 𝑦 ∗ ∗2
localhost:8888/notebooks/Python SEM4/Surface Plots- Jan 6th.ipynb# 5/6
1/20/24, 12:25 PM Surface Plots- Jan 6th - Jupyter Notebook

In [29]:  1 import matplotlib.pyplot as plt


2 x,y= meshgrid(linspace(-5, 5, 10), linspace(-5, 5, 10))
3 u= x/sqrt(x**2 + y**2)
4 v= y/sqrt(x**2 + y**2)
5 plt.quiver(x,y,u,v)
6 plt.show()

1 Conclusion: Overall we have explored the mpl_toolkits module and imported the
mplot3d functions. Moreover we have also learnt to plot 3-D Surface plots using
axes(), meshgrid() and projection() fucntions.

localhost:8888/notebooks/Python SEM4/Surface Plots- Jan 6th.ipynb# 6/6

You might also like