| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,6 +28,7 @@ | |||
| 28 | 28 | '../plot_types/arrays', | |
| 29 | 29 | '../plot_types/stats', | |
| 30 | 30 | '../plot_types/unstructured', | |
| 31 | + '../plot_types/3D', | ||
| 31 | 32 | ] | |
| 32 | 33 | ||
| 33 | 34 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,6 @@ | |||
| 1 | + .. _3D_plots: | ||
| 2 | + | ||
| 3 | + 3D | ||
| 4 | + -- | ||
| 5 | + | ||
| 6 | + 3D plot types. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,28 @@ | |||
| 1 | + """ | ||
| 2 | + ============== | ||
| 3 | + 3D scatterplot | ||
| 4 | + ============== | ||
| 5 | + | ||
| 6 | + See `~mpl_toolkits.mplot3d.axes3d.scatter`. | ||
| 7 | + """ | ||
| 8 | + import matplotlib.pyplot as plt | ||
| 9 | + import numpy as np | ||
| 10 | + | ||
| 11 | + plt.style.use('_mpl-gallery') | ||
| 12 | + | ||
| 13 | + np.random.seed(19680801) | ||
| 14 | + | ||
| 15 | + fig, ax = plt.subplots(subplot_kw={"projection": "3d"}) | ||
| 16 | + | ||
| 17 | + n = 100 | ||
| 18 | + | ||
| 19 | + # Make data | ||
| 20 | + rng = np.random.default_rng() | ||
| 21 | + xs = rng.uniform(23, 32, n) | ||
| 22 | + ys = rng.uniform(0, 100, n) | ||
| 23 | + zs = rng.uniform(-50, -25, n) | ||
| 24 | + | ||
| 25 | + # Plot | ||
| 26 | + ax.scatter(xs, ys, zs) | ||
| 27 | + | ||
| 28 | + plt.show() | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,25 @@ | |||
| 1 | + """ | ||
| 2 | + ===================== | ||
| 3 | + 3D surface | ||
| 4 | + ===================== | ||
| 5 | + | ||
| 6 | + See `~mpl_toolkits.mplot3d.axes3d.plot_surface`. | ||
| 7 | + """ | ||
| 8 | + import matplotlib.pyplot as plt | ||
| 9 | + import numpy as np | ||
| 10 | + | ||
| 11 | + plt.style.use('_mpl-gallery') | ||
| 12 | + | ||
| 13 | + fig, ax = plt.subplots(subplot_kw={"projection": "3d"}) | ||
| 14 | + | ||
| 15 | + # Make data | ||
| 16 | + X = np.arange(-5, 5, 0.25) | ||
| 17 | + Y = np.arange(-5, 5, 0.25) | ||
| 18 | + X, Y = np.meshgrid(X, Y) | ||
| 19 | + R = np.sqrt(X**2 + Y**2) | ||
| 20 | + Z = np.sin(R) | ||
| 21 | + | ||
| 22 | + # Plot the surface | ||
| 23 | + ax.plot_surface(X, Y, Z) | ||
| 24 | + | ||
| 25 | + plt.show() | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,30 @@ | |||
| 1 | + """ | ||
| 2 | + ====================== | ||
| 3 | + Triangular 3D surfaces | ||
| 4 | + ====================== | ||
| 5 | + | ||
| 6 | + See `~mpl_toolkits.mplot3d.axes3d.plot_trisurf`. | ||
| 7 | + """ | ||
| 8 | + import matplotlib.pyplot as plt | ||
| 9 | + import numpy as np | ||
| 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 | + fig, ax = plt.subplots(subplot_kw={'projection': '3d'}) | ||
| 27 | + | ||
| 28 | + ax.plot_trisurf(x, y, z) | ||
| 29 | + | ||
| 30 | + plt.show() | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,27 @@ | |||
| 1 | + """ | ||
| 2 | + ========================== | ||
| 3 | + 3D voxel / volumetric plot | ||
| 4 | + ========================== | ||
| 5 | + | ||
| 6 | + See `~mpl_toolkits.mplot3d.axes3d.voxels`. | ||
| 7 | + """ | ||
| 8 | + import matplotlib.pyplot as plt | ||
| 9 | + import numpy as np | ||
| 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 | ||
| 17 | + cube1 = (x < 3) & (y < 3) & (z < 3) | ||
| 18 | + cube2 = (x >= 5) & (y >= 5) & (z >= 5) | ||
| 19 | + | ||
| 20 | + # Combine the objects into a single boolean array | ||
| 21 | + voxelarray = cube1 | cube2 | ||
| 22 | + | ||
| 23 | + # Plot | ||
| 24 | + fig, ax = plt.subplots(subplot_kw={"projection": "3d"}) | ||
| 25 | + ax.voxels(voxelarray, edgecolor='k') | ||
| 26 | + | ||
| 27 | + plt.show() | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,21 @@ | |||
| 1 | + """ | ||
| 2 | + ================= | ||
| 3 | + 3D wireframe plot | ||
| 4 | + ================= | ||
| 5 | + | ||
| 6 | + See `~mpl_toolkits.mplot3d.axes3d.plot_wireframe`. | ||
| 7 | + """ | ||
| 8 | + from mpl_toolkits.mplot3d import axes3d | ||
| 9 | + import matplotlib.pyplot as plt | ||
| 10 | + | ||
| 11 | + plt.style.use('_mpl-gallery') | ||
| 12 | + | ||
| 13 | + fig, ax = plt.subplots(subplot_kw={"projection": "3d"}) | ||
| 14 | + | ||
| 15 | + # Make data | ||
| 16 | + X, Y, Z = axes3d.get_test_data(0.05) | ||
| 17 | + | ||
| 18 | + # Plot | ||
| 19 | + ax.plot_wireframe(X, Y, Z, rstride=10, cstride=10) | ||
| 20 | + | ||
| 21 | + plt.show() | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments