Python 3D Plot
Plot a ball
|
In this code, we first generate random points on the surface of a unit sphere using the numpy.random.uniform
function. Then we plot these points on a 3D scatter plot using matplotlib. Finally, we connect each point to the center of the sphere using a black dotted line with ax.plot
. The center of the sphere is defined as [0, 0, 0]
.
Add a plate to slice the dots
how to plot a surface
|
In this code, we first create a figure
and a subplot
with a 3D projection. Then, we generate some data for the surface plane using numpy.meshgrid()
. We set the z
values to zero so that the plane is on the xy
plane.
We then create the plane surface using Axes3D.plot_surface()
function. The alpha
parameter sets the transparency of the surface and the color
parameter sets its color.
Finally, we plot some 3D points using the Axes3D.scatter()
function.
When you run this code, you should see a 3D plot with a transparent blue plane surface and some randomly scattered 3D points.
Slice the ball with the surface
|
Python 3D Plot