Home
Locate
CS 101
CS 496
Login
Tutors
Marks
About
Send
Close
Add comments:
(status displays here)
Got it!
This site uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website.
nbsp; Note: This appears on each machine/browser from which this site is accessed.
Matplotlib: 3D plots
by RS
admin@ycp.powersoftwo.org
c
go
java
js
lua
py
vbs
rkt
scm
pro
1. Matplotlib: 3D plots
Matplotlib can be used to do 3D plots.
2. Scatter plot in 3d
Here is the Python code.
import matplotlib.pyplot as plt import rsPlot # required import to use 3d: from mpl_toolkits import mplot3d import numpy as np np.random.seed(12345) def randomRange1(n1, min1, max1): return (max1 - min1)*np.random.rand(n1) + min1 plot1 = rsPlot.plot("plot41-1") plot1.ax1 = plt.axes(projection="3d") fig1 = plot1.fig1 ax1 = plot1.ax1 ax1.set_xlabel("x domain") ax1.set_ylabel("y domain") ax1.set_zlabel("z range") n1 = 100 for m1, zlow1, zhigh1 in [("o", -50, -25), ("^", -30, -5)]: xs1 = randomRange1(n1, 23, 32) ys1 = randomRange1(n1, 0, 100) zs1 = randomRange1(n1, zlow1, zhigh1) ax1.scatter(xs1, ys1, zs1, marker=m1) plot1.save()
3. Output
Here is the output of the Python code.
(module rsPlot imported) ./plot41-1-01.png : 510 x 383 , 74,204 bytes
4. Image
5. Wire-frame plots in 3d
Matplotlib can be used for wire-frame plots.
Here is the Python code.
import matplotlib.pyplot as plt import rsPlot # required import to use 3d: from mpl_toolkits import mplot3d import numpy as np def fxy1(x1, y1): return np.sin(np.sqrt(x1*x1 + y1*y1)) plot1 = rsPlot.plot("plot41-2") plot1.ax1 = plt.axes(projection="3d") fig1 = plot1.fig1 ax1 = plot1.ax1 ax1.set_xlabel("x") ax1.set_ylabel("y") ax1.set_zlabel("z") xData1 = np.linspace(-5, 5, 20) yData1 = np.linspace(-5, 5, 20) xMesh1, yMesh1 = np.meshgrid(xData1,yData1) zData1 = fxy1(xMesh1, yMesh1) ax1.plot_wireframe(xMesh1, yMesh1, zData1, color="#000099") for pos1 in range(0, 7): angle1 = 15*pos1 print("Rotate: {0:d} degrees".format(angle1)) ax1.view_init(30,angle1) plot1.save()
Here is the output of the Python code.
(module rsPlot imported) Rotate: 0 degrees ./plot41-2-01.png : 510 x 383 , 100,571 bytes Rotate: 15 degrees ./plot41-2-02.png : 510 x 383 , 130,799 bytes Rotate: 30 degrees ./plot41-2-03.png : 510 x 383 , 136,890 bytes Rotate: 45 degrees ./plot41-2-04.png : 510 x 383 , 137,090 bytes Rotate: 60 degrees ./plot41-2-05.png : 510 x 383 , 136,074 bytes Rotate: 75 degrees ./plot41-2-06.png : 510 x 383 , 130,874 bytes Rotate: 90 degrees ./plot41-2-07.png : 510 x 383 , 100,363 bytes
6. End of page
by RS
admin@ycp.powersoftwo.org