Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5dfc6b1

Browse files
committed
DOC: Add 3D plots to plot_types gallery
1 parent4965500 commit5dfc6b1

File tree

7 files changed

+162
-0
lines changed

7 files changed

+162
-0
lines changed

‎doc/sphinxext/gallery_order.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
'../plot_types/arrays',
2929
'../plot_types/stats',
3030
'../plot_types/unstructured',
31+
'../plot_types/3D',
3132
]
3233

3334

‎plot_types/3D/README.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.. _3D_plots:
2+
3+
3D
4+
--
5+
6+
3D plot types.

‎plot_types/3D/scatter3d.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""
2+
==============
3+
3D scatterplot
4+
==============
5+
6+
Demonstration of a basic scatterplot in 3D.
7+
"""
8+
importmatplotlib.pyplotasplt
9+
importnumpyasnp
10+
11+
plt.style.use('_mpl-gallery')
12+
13+
np.random.seed(19680801)
14+
15+
16+
defrandrange(n,vmin,vmax):
17+
"""
18+
Helper function to make an array of random numbers having shape (n, )
19+
with each number distributed Uniform(vmin, vmax).
20+
"""
21+
return (vmax-vmin)*np.random.rand(n)+vmin
22+
23+
fig=plt.figure()
24+
ax=fig.add_subplot(projection='3d')
25+
26+
n=100
27+
28+
# Make data
29+
xs=randrange(n,23,32)
30+
ys=randrange(n,0,100)
31+
zs=randrange(n,-50,-25)
32+
33+
# Plot
34+
ax.scatter(xs,ys,zs)
35+
36+
plt.show()

‎plot_types/3D/surface3d.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""
2+
=====================
3+
3D surface (colormap)
4+
=====================
5+
6+
Demonstrates plotting a 3D surface colored with the coolwarm colormap.
7+
The surface is made opaque by using ``antialiased=False``.
8+
9+
Also demonstrates using the `.LinearLocator` and custom formatting for the
10+
z axis tick labels.
11+
"""
12+
importmatplotlib.pyplotasplt
13+
frommatplotlibimportcm
14+
importnumpyasnp
15+
16+
plt.style.use('_mpl-gallery')
17+
18+
fig,ax=plt.subplots(subplot_kw={"projection":"3d"})
19+
20+
# Make data
21+
X=np.arange(-5,5,0.25)
22+
Y=np.arange(-5,5,0.25)
23+
X,Y=np.meshgrid(X,Y)
24+
R=np.sqrt(X**2+Y**2)
25+
Z=np.sin(R)
26+
27+
# Plot the surface
28+
surf=ax.plot_surface(X,Y,Z,cmap=cm.coolwarm,
29+
linewidth=0,antialiased=False)
30+
31+
fig.colorbar(surf,shrink=0.5,aspect=5)
32+
33+
plt.show()

‎plot_types/3D/trisurf3d.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""
2+
======================
3+
Triangular 3D surfaces
4+
======================
5+
6+
Plot a 3D surface with a triangular mesh.
7+
"""
8+
importmatplotlib.pyplotasplt
9+
importnumpyasnp
10+
11+
plt.style.use('_mpl-gallery')
12+
13+
n_radii=8
14+
n_angles=36
15+
16+
# Make radii and angles spaces
17+
radii=np.linspace(0.125,1.0,n_radii)
18+
angles=np.linspace(0,2*np.pi,n_angles,endpoint=False)[...,np.newaxis]
19+
20+
# Convert polar (radii, angles) coords to cartesian (x, y) coords.
21+
x=np.append(0, (radii*np.cos(angles)).flatten())
22+
y=np.append(0, (radii*np.sin(angles)).flatten())
23+
z=np.sin(-x*y)
24+
25+
# Plot
26+
ax=plt.figure().add_subplot(projection='3d')
27+
28+
ax.plot_trisurf(x,y,z,linewidth=0.2,antialiased=True)
29+
30+
plt.show()

‎plot_types/3D/voxels.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
==========================
3+
3D voxel / volumetric plot
4+
==========================
5+
6+
Demonstrates plotting 3D volumetric objects with `.Axes3D.voxels`.
7+
"""
8+
importmatplotlib.pyplotasplt
9+
importnumpyasnp
10+
11+
plt.style.use('_mpl-gallery')
12+
13+
# Prepare some coordinates
14+
x,y,z=np.indices((8,8,8))
15+
16+
# Draw cuboids in the top left and bottom right corners, and a link between
17+
# them
18+
cube1= (x<3)& (y<3)& (z<3)
19+
cube2= (x>=5)& (y>=5)& (z>=5)
20+
link=abs(x-y)+abs(y-z)+abs(z-x)<=2
21+
22+
# Combine the objects into a single boolean array
23+
voxelarray=cube1|cube2|link
24+
25+
colors=np.empty(voxelarray.shape,dtype=object)
26+
colors[link]='red'
27+
colors[cube1]='blue'
28+
colors[cube2]='green'
29+
30+
# Plot
31+
ax=plt.figure().add_subplot(projection='3d')
32+
ax.voxels(voxelarray,facecolors=colors,edgecolor='k')
33+
34+
plt.show()

‎plot_types/3D/wire3d.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""
2+
=================
3+
3D wireframe plot
4+
=================
5+
6+
A very basic demonstration of a wireframe plot.
7+
"""
8+
frommpl_toolkits.mplot3dimportaxes3d
9+
importmatplotlib.pyplotasplt
10+
11+
plt.style.use('_mpl-gallery')
12+
13+
fig=plt.figure()
14+
ax=fig.add_subplot(projection='3d')
15+
16+
# Make data
17+
X,Y,Z=axes3d.get_test_data(0.05)
18+
19+
# Plot
20+
ax.plot_wireframe(X,Y,Z,rstride=10,cstride=10)
21+
22+
plt.show()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp