| [ Web Proxy ] |
| Viewing: https://matplotlib.org/stable/api/_as_gen/../../gallery/misc/../scales/../mplot3d/polys3d.html | [Back] [Original] |
Section Navigation
fill_between with transparencyhisttype settingsplt.subplotsfloating_axes featuresNote
Go to the end to download the full example code.
Demonstrate how to create polygons in 3D. Here we stack 3 hexagons.
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
# Coordinates of a hexagon
angles = np.linspace(0, 2 * np.pi, 6, endpoint=False)
x = np.cos(angles)
y = np.sin(angles)
zs = [-3, -2, -1]
# Close the hexagon by repeating the first vertex
x = np.append(x, x[0])
y = np.append(y, y[0])
verts = []
for z in zs:
verts.append(list(zip(x*z, y*z, np.full_like(x, z))))
verts = np.array(verts)
ax = plt.figure().add_subplot(projection='3d')
poly = Poly3DCollection(verts, alpha=.7)
ax.add_collection3d(poly)
ax.set_aspect('equalxy')
plt.show()
[polys3d]Tags: plot-type: 3D styling: colormap level: intermediate
Copyright 20022012 John Hunter, Darren Dale, Eric Firing, Michael Droettboom and the Matplotlib development team; 20122026 The Matplotlib development team.
Created using Sphinx 9.1.0.
Built from v3.11.2-1-g879ad8ebba.
Built with the PyData Sphinx Theme 0.16.1.
| Web Proxy Viewer | New URL | Original Page |