Skip to main content
Ctrl+K
You are reading documentation for the unreleased version of Matplotlib. Try searching for the released version of this page instead?
Matplotlib 3.10.1+dfsg1 documentation - Home Matplotlib 3.10.1+dfsg1 documentation - Home
  • Plot types
  • User guide
  • Tutorials
  • Examples
  • Reference
  • Contribute
  • Releases
  • Gitter
  • Discourse
  • GitHub
  • Twitter
  • Plot types
  • User guide
  • Tutorials
  • Examples
  • Reference
  • Contribute
  • Releases
  • Gitter
  • Discourse
  • GitHub
  • Twitter

Section Navigation

  • Lines, bars and markers
  • Images, contours and fields
  • Subplots, axes and figures
  • Statistics
  • Pie and polar charts
  • Text, labels and annotations
  • Color
  • Shapes and collections
  • Style sheets
  • Module - pyplot
  • Module - axes_grid1
  • Module - axisartist
  • Showcase
  • Animation
  • Event handling
  • Miscellaneous
  • 3D plotting
    • Plot 2D data on 3D plot
    • Demo of 3D bar charts
    • Clip the data to the axes view limits
    • Create 2D bar graphs in different planes
    • 3D box surface plot
    • Plot contour (level) curves in 3D
    • Plot contour (level) curves in 3D using the extend3d option
    • Project contour profiles onto a graph
    • Filled contours
    • Project filled contour onto a graph
    • Custom hillshading in a 3D surface plot
    • 3D errorbars
    • Fill between 3D lines
    • Fill under 3D line graphs
    • Create 3D histogram of 2D data
    • 2D images in 3D
    • Intersecting planes
    • Parametric curve
    • Lorenz attractor
    • 2D and 3D Axes in same figure
    • Automatic text offsetting
    • Draw flat objects in 3D plot
    • Generate 3D polygons
    • 3D plot projection types
    • 3D quiver plot
    • Rotating a 3D plot
    • 3D scatterplot
    • 3D stem
    • 3D plots as subplots
    • 3D surface (colormap)
    • 3D surface (solid color)
    • 3D surface (checkerboard)
    • 3D surface with polar coordinates
    • Text annotations in 3D
    • Triangular 3D contour plot
    • Triangular 3D filled contour plot
    • Triangular 3D surfaces
    • More triangular 3D surfaces
    • Primary 3D view planes
    • 3D voxel / volumetric plot
    • 3D voxel plot of the NumPy logo
    • 3D voxel / volumetric plot with RGB colors
    • 3D voxel / volumetric plot with cylindrical coordinates
    • 3D wireframe plot
    • Animate a 3D wireframe plot
    • 3D wireframe plots in one direction
  • Scales
  • Specialty plots
  • Spines
  • Ticks
  • Units
  • Embedding Matplotlib in graphical user interfaces
  • Widgets
  • Userdemo
  • Examples
  • 3D plotting
  • 3D voxel plot of the NumPy logo

Note

Go to the end to download the full example code.

3D voxel plot of the NumPy logo#

Demonstrates using Axes3D.voxels with uneven coordinates.

import matplotlib.pyplot as plt
import numpy as np


def explode(data):
    size = np.array(data.shape)*2
    data_e = np.zeros(size - 1, dtype=data.dtype)
    data_e[::2, ::2, ::2] = data
    return data_e

# build up the numpy logo
n_voxels = np.zeros((4, 3, 4), dtype=bool)
n_voxels[0, 0, :] = True
n_voxels[-1, 0, :] = True
n_voxels[1, 0, 2] = True
n_voxels[2, 0, 1] = True
facecolors = np.where(n_voxels, '#FFD65DC0', '#7A88CCC0')
edgecolors = np.where(n_voxels, '#BFAB6E', '#7D84A6')
filled = np.ones(n_voxels.shape)

# upscale the above voxel image, leaving gaps
filled_2 = explode(filled)
fcolors_2 = explode(facecolors)
ecolors_2 = explode(edgecolors)

# Shrink the gaps
x, y, z = np.indices(np.array(filled_2.shape) + 1).astype(float) // 2
x[0::2, :, :] += 0.05
y[:, 0::2, :] += 0.05
z[:, :, 0::2] += 0.05
x[1::2, :, :] += 0.95
y[:, 1::2, :] += 0.95
z[:, :, 1::2] += 0.95

ax = plt.figure().add_subplot(projection='3d')
ax.voxels(x, y, z, filled_2, facecolors=fcolors_2, edgecolors=ecolors_2)
ax.set_aspect('equal')

plt.show()

Download Jupyter notebook: voxels_numpy_logo.ipynb

Download Python source code: voxels_numpy_logo.py

Download zipped: voxels_numpy_logo.zip

Gallery generated by Sphinx-Gallery

© Copyright 2002–2012 John Hunter, Darren Dale, Eric Firing, Michael Droettboom and the Matplotlib development team; 2012–2025 The Matplotlib development team.

Created using Sphinx 8.1.3.

Built from 3.10.1+dfsg1.

Built with the PyData Sphinx Theme 0.16.1.