3d

Overview

3D charting represents data in three coordinates so analysts can inspect structure that is hard to see in 2D, such as curvature, spatial gradients, and multivariable interactions. In scientific and engineering work, these views are a core part of scientific visualization, where shape and orientation often carry as much meaning as magnitude. This category provides spreadsheet-friendly wrappers for common 3D plot families so teams can move from tabular data to interpretable geometry quickly. It is especially useful for exploratory analysis, simulation review, and communicating spatial patterns to non-specialist audiences.

Across these tools, the unifying ideas are Cartesian coordinates (x,y,z), geometric primitives (points, lines, surfaces, and volumes), and visual encodings (color, transparency, marker style, and grid density). Surface-style functions often model relationships in the form z=f(x,y), while point and vector functions emphasize discrete observations or direction fields. Practical interpretation depends on balancing occlusion, depth cues, and color mapping so that 3D structure clarifies rather than obscures the data.

Implementation is built on Matplotlib and its mplot3d toolkit, the standard Python stack for programmatic 3D plotting. Matplotlib is widely used for reproducible technical graphics, and these wrappers expose that capability through Excel-style function signatures while still returning native figure objects in standard Python contexts.

AREA_3D focuses on filled geometry between two 3D curves, making it useful when the region between trajectories is analytically important, such as envelope comparisons or gap visualization. Unlike pure line views, it emphasizes extent and separation through both polygon fill and alpha blending. It pairs well with axis labels and transparency controls when comparing alternative paths or boundaries in design and physics data.

LINE_3D, SCATTER_3D, and STEM_3D cover trajectory and point-based exploration. LINE_3D is best for ordered sequences and path evolution, SCATTER_3D is better for unordered clouds and cluster structure, and STEM_3D highlights distance from a reference axis to emphasize magnitude at each coordinate. Together they support use cases like sensor traces, design-space sampling, and quick outlier inspection.

BAR_3D, QUIVER_3D, and VOXELS handle discrete 3D magnitudes, direction fields, and occupancy grids. BAR_3D encodes values as extruded columns at (x,y) locations, QUIVER_3D encodes vector direction and relative intensity through arrows, and VOXELS renders boolean 3D cells for volumetric structures. These are practical for binned summaries, flow-field diagnostics, and block-based models used in imaging, geospatial indexing, or simulation masks.

SURFACE_3D, TRISURF_3D, and WIREFRAME_3D address continuous surface modeling with different mesh assumptions. SURFACE_3D is suited to gridded matrices and supports colormaps plus colorbars for value interpretation, WIREFRAME_3D exposes mesh structure for topology-focused diagnostics, and TRISURF_3D handles irregularly spaced points via triangular tessellation. In practice, analysts choose among them based on data regularity, the need for quantitative color encoding, and whether mesh visibility or surface realism is the primary goal.

AREA_3D

Create a 3D filled area chart between two 3D lines.

Excel Usage

=AREA_3D(data, title, xlabel, ylabel, zlabel, area_color, alpha)
  • data (list[list], required): Input data with 6 columns (X1, Y1, Z1, X2, Y2, Z2).
  • title (str, optional, default: null): Chart title.
  • xlabel (str, optional, default: null): Label for X-axis.
  • ylabel (str, optional, default: null): Label for Y-axis.
  • zlabel (str, optional, default: null): Label for Z-axis.
  • area_color (str, optional, default: null): Area color.
  • alpha (float, optional, default: 0.5): Alpha transparency.

Returns (object): Matplotlib Figure object (standard Python) or base64 encoded PNG string (Pyodide).

Example 1: 3D double helix area

Inputs:

data title
1 0 0 -1 0 0 3D Helix Area
0.707 0.707 0.25 -0.707 -0.707 0.25
0 1 0.5 0 -1 0.5
-0.707 0.707 0.75 0.707 -0.707 0.75
-1 0 1 1 0 1

Excel formula:

=AREA_3D({1,0,0,-1,0,0;0.707,0.707,0.25,-0.707,-0.707,0.25;0,1,0.5,0,-1,0.5;-0.707,0.707,0.75,0.707,-0.707,0.75;-1,0,1,1,0,1}, "3D Helix Area")

Expected output:

"chart"

Example 2: Simple column data

Inputs:

data
0 0 0 1 1 0
0 1 1 1 0 1

Excel formula:

=AREA_3D({0,0,0,1,1,0;0,1,1,1,0,1})

Expected output:

"chart"

Example 3: Blue area with high transparency

Inputs:

data area_color alpha
0 0 0 1 1 1 blue 0.3
1 0 1 0 1 0

Excel formula:

=AREA_3D({0,0,0,1,1,1;1,0,1,0,1,0}, "blue", 0.3)

Expected output:

"chart"

Example 4: Green area with title

Inputs:

data area_color title
0 0 0 2 2 2 green Green 3D Area
2 0 2 0 2 0

Excel formula:

=AREA_3D({0,0,0,2,2,2;2,0,2,0,2,0}, "green", "Green 3D Area")

Expected output:

"chart"

Python Code

Show Code
import sys
import matplotlib
IS_PYODIDE = sys.platform == "emscripten"
if IS_PYODIDE:
    matplotlib.use('Agg')
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
import io
import base64
import numpy as np

def area_3d(data, title=None, xlabel=None, ylabel=None, zlabel=None, area_color=None, alpha=0.5):
    """
    Create a 3D filled area chart between two 3D lines.

    See: https://matplotlib.org/stable/api/_as_gen/mpl_toolkits.mplot3d.axes3d.Axes3D.fill_between.html

    This example function is provided as-is without any representation of accuracy.

    Args:
        data (list[list]): Input data with 6 columns (X1, Y1, Z1, X2, Y2, Z2).
        title (str, optional): Chart title. Default is None.
        xlabel (str, optional): Label for X-axis. Default is None.
        ylabel (str, optional): Label for Y-axis. Default is None.
        zlabel (str, optional): Label for Z-axis. Default is None.
        area_color (str, optional): Area color. Valid options: Blue, Green, Red, Cyan, Magenta, Yellow, Black, White. Default is None.
        alpha (float, optional): Alpha transparency. Default is 0.5.

    Returns:
        object: Matplotlib Figure object (standard Python) or base64 encoded PNG string (Pyodide).
    """
    def to2d(x):
        return [[x]] if not isinstance(x, list) else x

    try:
        data = to2d(data)
        if not isinstance(data, list) or not data or not isinstance(data[0], list):
            return "Error: Input data must be a 2D list."

        arr = np.array(data, dtype=float)
        if arr.shape[1] < 6:
            return "Error: Data must have at least 6 columns (X1, Y1, Z1, X2, Y2, Z2)."

        x1, y1, z1 = arr[:, 0], arr[:, 1], arr[:, 2]
        x2, y2, z2 = arr[:, 3], arr[:, 4], arr[:, 5]

        # Create figure with 3D projection
        fig, ax = plt.subplots(figsize=(10, 7), subplot_kw={"projection": "3d"})

        # Determine color and alpha
        c = area_color if area_color and area_color != "" else "C0"
        a = float(alpha) if alpha is not None else 0.5

        # Use Poly3DCollection for compatibility with Matplotlib < 3.10
        verts = []
        for i in range(len(x1) - 1):
            vtx = [
                (x1[i], y1[i], z1[i]),
                (x1[i+1], y1[i+1], z1[i+1]),
                (x2[i+1], y2[i+1], z2[i+1]),
                (x2[i], y2[i], z2[i])
            ]
            verts.append(vtx)

        poly = Poly3DCollection(verts, alpha=a, facecolor=c)
        ax.add_collection3d(poly)

        # Plot lines for clarity
        ax.plot(x1, y1, z1, linewidth=2, color=c)
        ax.plot(x2, y2, z2, linewidth=2, color=c)

        if title: ax.set_title(title)
        if xlabel: ax.set_xlabel(xlabel)
        if ylabel: ax.set_ylabel(ylabel)
        if zlabel: ax.set_zlabel(zlabel)

        ax.set(xticklabels=[], yticklabels=[], zticklabels=[])
        plt.tight_layout()

        if IS_PYODIDE:
            buf = io.BytesIO()
            plt.savefig(buf, format='png')
            plt.close(fig)
            buf.seek(0)
            img_b64 = base64.b64encode(buf.read()).decode('utf-8')
            return f"data:image/png;base64,{img_b64}"
        else:
            return fig
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Input data with 6 columns (X1, Y1, Z1, X2, Y2, Z2).
Chart title.
Label for X-axis.
Label for Y-axis.
Label for Z-axis.
Area color.
Alpha transparency.

BAR_3D

Create a 3D bar chart.

Excel Usage

=BAR_3D(data, title, xlabel, ylabel, zlabel, color_map, legend)
  • data (list[list], required): Input data (X, Y, Z).
  • title (str, optional, default: null): Chart title.
  • xlabel (str, optional, default: null): Label for X-axis.
  • ylabel (str, optional, default: null): Label for Y-axis.
  • zlabel (str, optional, default: null): Label for Z-axis.
  • color_map (str, optional, default: “viridis”): Color map for bars.
  • legend (str, optional, default: “false”): Show legend.

Returns (object): Matplotlib Figure object (standard Python) or base64 encoded PNG string (Pyodide).

Example 1: Basic 3D bar chart

Inputs:

data
0 0 1
1 0 2
0 1 3
1 1 4

Excel formula:

=BAR_3D({0,0,1;1,0,2;0,1,3;1,1,4})

Expected output:

"chart"

Example 2: 3D bars with labels

Inputs:

data title xlabel ylabel zlabel
0 0 5 Bar Chart X Y Height
1 0 10
0 1 15
1 1 20

Excel formula:

=BAR_3D({0,0,5;1,0,10;0,1,15;1,1,20}, "Bar Chart", "X", "Y", "Height")

Expected output:

"chart"

Example 3: Using plasma colormap

Inputs:

data color_map
0 0 2 plasma
1 0 4
2 0 6
0 1 8

Excel formula:

=BAR_3D({0,0,2;1,0,4;2,0,6;0,1,8}, "plasma")

Expected output:

"chart"

Example 4: Bars with legend

Inputs:

data legend
0 0 1 true
1 0 2
0 1 3

Excel formula:

=BAR_3D({0,0,1;1,0,2;0,1,3}, "true")

Expected output:

"chart"

Python Code

Show Code
import sys
import matplotlib
IS_PYODIDE = sys.platform == "emscripten"
if IS_PYODIDE:
    matplotlib.use('Agg')
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import io
import base64
import numpy as np

def bar_3d(data, title=None, xlabel=None, ylabel=None, zlabel=None, color_map='viridis', legend='false'):
    """
    Create a 3D bar chart.

    See: https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.bar3d.html

    This example function is provided as-is without any representation of accuracy.

    Args:
        data (list[list]): Input data (X, Y, Z).
        title (str, optional): Chart title. Default is None.
        xlabel (str, optional): Label for X-axis. Default is None.
        ylabel (str, optional): Label for Y-axis. Default is None.
        zlabel (str, optional): Label for Z-axis. Default is None.
        color_map (str, optional): Color map for bars. Valid options: Viridis, Plasma, Inferno, Magma, Cividis. Default is 'viridis'.
        legend (str, optional): Show legend. Valid options: True, False. Default is 'false'.

    Returns:
        object: Matplotlib Figure object (standard Python) or base64 encoded PNG string (Pyodide).
    """
    def to2d(x):
        return [[x]] if not isinstance(x, list) else x

    try:
        data = to2d(data)

        if not isinstance(data, list) or not all(isinstance(row, list) for row in data):
            return "Error: Invalid input - data must be a 2D list"

        # Flatten and validate data
        flat_data = []
        for row in data:
            for val in row:
                try:
                    flat_data.append(float(val))
                except (TypeError, ValueError):
                    return f"Error: Non-numeric value found: {val}"

        if len(flat_data) < 3:
            return "Error: Need at least 3 values for X, Y, Z coordinates"

        # Parse data into columns
        num_rows = len(data)
        num_cols = len(data[0]) if num_rows > 0 else 0

        if num_cols < 3:
            return "Error: Need at least 3 columns for X, Y, Z coordinates"

        # Extract X, Y, Z columns
        x_vals = np.array([float(data[i][0]) for i in range(num_rows)])
        y_vals = np.array([float(data[i][1]) for i in range(num_rows)])
        z_vals = np.array([float(data[i][2]) for i in range(num_rows)])

        # Create figure
        fig = plt.figure(figsize=(10, 7))
        ax = fig.add_subplot(111, projection='3d')

        # Bar dimensions
        dx = dy = 0.5  # Bar width
        dz = z_vals  # Bar heights

        # Color mapping
        cmap = plt.get_cmap(color_map)
        colors = cmap(z_vals / z_vals.max())

        # Create 3D bar chart
        ax.bar3d(x_vals, y_vals, np.zeros(len(z_vals)), dx, dy, dz, color=colors, shade=True)

        # Set labels
        if title:
            ax.set_title(title)
        if xlabel:
            ax.set_xlabel(xlabel)
        if ylabel:
            ax.set_ylabel(ylabel)
        if zlabel:
            ax.set_zlabel(zlabel)

        # Add legend if requested
        if legend == "true":
            ax.legend(['Bars'])

        # Return based on platform
        if IS_PYODIDE:
            buf = io.BytesIO()
            plt.savefig(buf, format='png', dpi=100, bbox_inches='tight')
            buf.seek(0)
            img_base64 = base64.b64encode(buf.read()).decode('utf-8')
            plt.close(fig)
            return f"data:image/png;base64,{img_base64}"
        else:
            return fig
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Input data (X, Y, Z).
Chart title.
Label for X-axis.
Label for Y-axis.
Label for Z-axis.
Color map for bars.
Show legend.

LINE_3D

Create a 3D line plot.

Excel Usage

=LINE_3D(data, title, xlabel, ylabel, zlabel, plot_color, linestyle, legend)
  • data (list[list], required): Input data (X, Y, Z).
  • title (str, optional, default: null): Chart title.
  • xlabel (str, optional, default: null): Label for X-axis.
  • ylabel (str, optional, default: null): Label for Y-axis.
  • zlabel (str, optional, default: null): Label for Z-axis.
  • plot_color (str, optional, default: null): Line color.
  • linestyle (str, optional, default: “-”): Line style.
  • legend (str, optional, default: “false”): Show legend.

Returns (object): Matplotlib Figure object (standard Python) or base64 encoded PNG string (Pyodide).

Example 1: Basic 3D line plot

Inputs:

data
0 0 0
1 1 1
2 2 2
3 3 3

Excel formula:

=LINE_3D({0,0,0;1,1,1;2,2,2;3,3,3})

Expected output:

"chart"

Example 2: 3D line with labels

Inputs:

data title xlabel ylabel zlabel
0 0 1 Line Plot X Y Z
1 1 2
2 4 3
3 9 4

Excel formula:

=LINE_3D({0,0,1;1,1,2;2,4,3;3,9,4}, "Line Plot", "X", "Y", "Z")

Expected output:

"chart"

Example 3: Red dashed line

Inputs:

data plot_color linestyle
1 2 1 red
2 3 2
3 4 3
4 5 4

Excel formula:

=LINE_3D({1,2,1;2,3,2;3,4,3;4,5,4}, "red", "--")

Expected output:

"chart"

Example 4: Line with legend

Inputs:

data legend
0 1 0 true
1 2 1
2 3 2
3 4 3

Excel formula:

=LINE_3D({0,1,0;1,2,1;2,3,2;3,4,3}, "true")

Expected output:

"chart"

Python Code

Show Code
import sys
import matplotlib
IS_PYODIDE = sys.platform == "emscripten"
if IS_PYODIDE:
    matplotlib.use('Agg')
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import io
import base64
import numpy as np

def line_3d(data, title=None, xlabel=None, ylabel=None, zlabel=None, plot_color=None, linestyle='-', legend='false'):
    """
    Create a 3D line plot.

    See: https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.plot.html#matplotlib.axes.Axes.plot

    This example function is provided as-is without any representation of accuracy.

    Args:
        data (list[list]): Input data (X, Y, Z).
        title (str, optional): Chart title. Default is None.
        xlabel (str, optional): Label for X-axis. Default is None.
        ylabel (str, optional): Label for Y-axis. Default is None.
        zlabel (str, optional): Label for Z-axis. Default is None.
        plot_color (str, optional): Line color. Valid options: Blue, Green, Red, Cyan, Magenta, Yellow, Black, White. Default is None.
        linestyle (str, optional): Line style. Valid options: Solid, Dashed, Dotted, Dash-dot. Default is '-'.
        legend (str, optional): Show legend. Valid options: True, False. Default is 'false'.

    Returns:
        object: Matplotlib Figure object (standard Python) or base64 encoded PNG string (Pyodide).
    """
    def to2d(x):
        return [[x]] if not isinstance(x, list) else x

    try:
        data = to2d(data)

        if not isinstance(data, list) or not all(isinstance(row, list) for row in data):
            return "Error: Invalid input - data must be a 2D list"

        # Flatten and validate data
        flat_data = []
        for row in data:
            for val in row:
                try:
                    flat_data.append(float(val))
                except (TypeError, ValueError):
                    return f"Error: Non-numeric value found: {val}"

        if len(flat_data) < 3:
            return "Error: Need at least 3 values for X, Y, Z coordinates"

        # Parse data into columns
        num_rows = len(data)
        num_cols = len(data[0]) if num_rows > 0 else 0

        if num_cols < 3:
            return "Error: Need at least 3 columns for X, Y, Z coordinates"

        # Extract X, Y, Z columns
        x_vals = [float(data[i][0]) for i in range(num_rows)]
        y_vals = [float(data[i][1]) for i in range(num_rows)]
        z_vals = [float(data[i][2]) for i in range(num_rows)]

        # Create figure
        fig = plt.figure(figsize=(10, 7))
        ax = fig.add_subplot(111, projection='3d')

        # Create line plot
        if plot_color:
            ax.plot(x_vals, y_vals, z_vals, color=plot_color, linestyle=linestyle, linewidth=2)
        else:
            ax.plot(x_vals, y_vals, z_vals, linestyle=linestyle, linewidth=2)

        # Set labels
        if title:
            ax.set_title(title)
        if xlabel:
            ax.set_xlabel(xlabel)
        if ylabel:
            ax.set_ylabel(ylabel)
        if zlabel:
            ax.set_zlabel(zlabel)

        # Add legend if requested
        if legend == "true":
            ax.legend(['Line 1'])

        # Return based on platform
        if IS_PYODIDE:
            buf = io.BytesIO()
            plt.savefig(buf, format='png', dpi=100, bbox_inches='tight')
            buf.seek(0)
            img_base64 = base64.b64encode(buf.read()).decode('utf-8')
            plt.close(fig)
            return f"data:image/png;base64,{img_base64}"
        else:
            return fig
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Input data (X, Y, Z).
Chart title.
Label for X-axis.
Label for Y-axis.
Label for Z-axis.
Line color.
Line style.
Show legend.

QUIVER_3D

Create a 3D quiver (vector) plot.

Excel Usage

=QUIVER_3D(data, title, xlabel, ylabel, zlabel, length, normalize)
  • data (list[list], required): Input data (X, Y, Z, U, V, W).
  • title (str, optional, default: null): Chart title.
  • xlabel (str, optional, default: null): Label for X-axis.
  • ylabel (str, optional, default: null): Label for Y-axis.
  • zlabel (str, optional, default: null): Label for Z-axis.
  • length (float, optional, default: 0.1): Length of each quiver.
  • normalize (bool, optional, default: false): Normalize the arrows to have the same length.

Returns (object): Matplotlib Figure object (standard Python) or base64 encoded PNG string (Pyodide).

Example 1: Basic 3D quiver plot

Inputs:

data
0 0 0 1 0 0
0 0 0 0 1 0
0 0 0 0 0 1

Excel formula:

=QUIVER_3D({0,0,0,1,0,0;0,0,0,0,1,0;0,0,0,0,0,1})

Expected output:

"chart"

Example 2: 3D quiver with labels

Inputs:

data title xlabel ylabel zlabel
0 0 0 1 1 1 Vector Field X Y Z

Excel formula:

=QUIVER_3D({0,0,0,1,1,1}, "Vector Field", "X", "Y", "Z")

Expected output:

"chart"

Example 3: Custom length arrows

Inputs:

data length
0 0 0 1 0 0 0.5
1 1 1 0 1 0

Excel formula:

=QUIVER_3D({0,0,0,1,0,0;1,1,1,0,1,0}, 0.5)

Expected output:

"chart"

Example 4: Simple quiver plot

Inputs:

data
0 0 0 1 0 0
0 0 0 0 1 0
0 0 0 0 0 1

Excel formula:

=QUIVER_3D({0,0,0,1,0,0;0,0,0,0,1,0;0,0,0,0,0,1})

Expected output:

"chart"

Example 5: Multiple arrows

Inputs:

data
0 0 0 1 0 0
0 0 0 0 1 0
0 0 0 0 0 1

Excel formula:

=QUIVER_3D({0,0,0,1,0,0;0,0,0,0,1,0;0,0,0,0,0,1})

Expected output:

"chart"

Example 6: Quiver with color array

Inputs:

data
0 0 0 1 0 0
0 0 0 0 1 0
0 0 0 0 0 1

Excel formula:

=QUIVER_3D({0,0,0,1,0,0;0,0,0,0,1,0;0,0,0,0,0,1})

Expected output:

"chart"

Python Code

Show Code
import sys
import matplotlib
IS_PYODIDE = sys.platform == "emscripten"
if IS_PYODIDE:
    matplotlib.use('Agg')
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import io
import base64
import numpy as np

def quiver_3d(data, title=None, xlabel=None, ylabel=None, zlabel=None, length=0.1, normalize=False):
    """
    Create a 3D quiver (vector) plot.

    See: https://matplotlib.org/stable/api/_as_gen/mpl_toolkits.mplot3d.axes3d.Axes3D.quiver.html

    This example function is provided as-is without any representation of accuracy.

    Args:
        data (list[list]): Input data (X, Y, Z, U, V, W).
        title (str, optional): Chart title. Default is None.
        xlabel (str, optional): Label for X-axis. Default is None.
        ylabel (str, optional): Label for Y-axis. Default is None.
        zlabel (str, optional): Label for Z-axis. Default is None.
        length (float, optional): Length of each quiver. Default is 0.1.
        normalize (bool, optional): Normalize the arrows to have the same length. Default is False.

    Returns:
        object: Matplotlib Figure object (standard Python) or base64 encoded PNG string (Pyodide).
    """
    def to2d(x):
        return [[x]] if not isinstance(x, list) else x

    try:
        data = to2d(data)

        if not isinstance(data, list) or not all(isinstance(row, list) for row in data):
            return "Error: Invalid input - data must be a 2D list"

        # Validate dimensions
        num_rows = len(data)
        num_cols = len(data[0]) if num_rows > 0 else 0

        if num_cols < 6:
            return "Error: Need at least 6 columns for X, Y, Z coordinates and U, V, W vectors"

        # Extract and validate columns
        try:
            x_vals = np.array([float(data[i][0]) for i in range(num_rows)])
            y_vals = np.array([float(data[i][1]) for i in range(num_rows)])
            z_vals = np.array([float(data[i][2]) for i in range(num_rows)])
            u_vals = np.array([float(data[i][3]) for i in range(num_rows)])
            v_vals = np.array([float(data[i][4]) for i in range(num_rows)])
            w_vals = np.array([float(data[i][5]) for i in range(num_rows)])
        except (ValueError, TypeError, IndexError):
            return "Error: Input data contains non-numeric values or missing columns"

        # Create figure
        fig = plt.figure(figsize=(10, 7))
        ax = fig.add_subplot(111, projection='3d')

        # Create quiver plot
        ax.quiver(x_vals, y_vals, z_vals, u_vals, v_vals, w_vals, length=length, normalize=normalize)

        # Set labels
        if title:
            ax.set_title(title)
        if xlabel:
            ax.set_xlabel(xlabel)
        if ylabel:
            ax.set_ylabel(ylabel)
        if zlabel:
            ax.set_zlabel(zlabel)

        # Return based on platform
        if IS_PYODIDE:
            buf = io.BytesIO()
            plt.savefig(buf, format='png', dpi=100, bbox_inches='tight')
            buf.seek(0)
            img_base64 = base64.b64encode(buf.read()).decode('utf-8')
            plt.close(fig)
            return f"data:image/png;base64,{img_base64}"
        else:
            return fig
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Input data (X, Y, Z, U, V, W).
Chart title.
Label for X-axis.
Label for Y-axis.
Label for Z-axis.
Length of each quiver.
Normalize the arrows to have the same length.

SCATTER_3D

Create a 3D scatter plot.

Excel Usage

=SCATTER_3D(data, title, xlabel, ylabel, zlabel, color_map, marker, legend)
  • data (list[list], required): Input data (X, Y, Z).
  • title (str, optional, default: null): Chart title.
  • xlabel (str, optional, default: null): Label for X-axis.
  • ylabel (str, optional, default: null): Label for Y-axis.
  • zlabel (str, optional, default: null): Label for Z-axis.
  • color_map (str, optional, default: “viridis”): Color map for points.
  • marker (str, optional, default: “o”): Marker style.
  • legend (str, optional, default: “false”): Show legend.

Returns (object): Matplotlib Figure object (standard Python) or base64 encoded PNG string (Pyodide).

Example 1: Basic 3D scatter plot

Inputs:

data
1 2 3
2 3 4
3 4 5
4 5 6

Excel formula:

=SCATTER_3D({1,2,3;2,3,4;3,4,5;4,5,6})

Expected output:

"chart"

Example 2: 3D scatter with labels

Inputs:

data title xlabel ylabel zlabel
1 1 1 Scatter Plot X Y Z
2 4 2
3 9 3
4 16 4

Excel formula:

=SCATTER_3D({1,1,1;2,4,2;3,9,3;4,16,4}, "Scatter Plot", "X", "Y", "Z")

Expected output:

"chart"

Example 3: Using plasma colormap

Inputs:

data color_map
0 0 1 plasma
1 1 2
2 2 3
3 3 4
4 4 5

Excel formula:

=SCATTER_3D({0,0,1;1,1,2;2,2,3;3,3,4;4,4,5}, "plasma")

Expected output:

"chart"

Example 4: Using square markers

Inputs:

data marker legend
1 2 1 s true
2 3 2
3 4 3
4 5 4

Excel formula:

=SCATTER_3D({1,2,1;2,3,2;3,4,3;4,5,4}, "s", "true")

Expected output:

"chart"

Python Code

Show Code
import sys
import matplotlib
IS_PYODIDE = sys.platform == "emscripten"
if IS_PYODIDE:
    matplotlib.use('Agg')
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import io
import base64
import numpy as np

def scatter_3d(data, title=None, xlabel=None, ylabel=None, zlabel=None, color_map='viridis', marker='o', legend='false'):
    """
    Create a 3D scatter plot.

    See: https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.scatter.html#matplotlib.axes.Axes.scatter

    This example function is provided as-is without any representation of accuracy.

    Args:
        data (list[list]): Input data (X, Y, Z).
        title (str, optional): Chart title. Default is None.
        xlabel (str, optional): Label for X-axis. Default is None.
        ylabel (str, optional): Label for Y-axis. Default is None.
        zlabel (str, optional): Label for Z-axis. Default is None.
        color_map (str, optional): Color map for points. Valid options: Viridis, Plasma, Inferno, Magma, Cividis. Default is 'viridis'.
        marker (str, optional): Marker style. Valid options: None, Point, Pixel, Circle, Square, Triangle Down, Triangle Up. Default is 'o'.
        legend (str, optional): Show legend. Valid options: True, False. Default is 'false'.

    Returns:
        object: Matplotlib Figure object (standard Python) or base64 encoded PNG string (Pyodide).
    """
    def to2d(x):
        return [[x]] if not isinstance(x, list) else x

    try:
        data = to2d(data)

        if not isinstance(data, list) or not all(isinstance(row, list) for row in data):
            return "Error: Invalid input - data must be a 2D list"

        # Flatten and validate data
        flat_data = []
        for row in data:
            for val in row:
                try:
                    flat_data.append(float(val))
                except (TypeError, ValueError):
                    return f"Error: Non-numeric value found: {val}"

        if len(flat_data) < 3:
            return "Error: Need at least 3 values for X, Y, Z coordinates"

        # Parse data into columns
        num_rows = len(data)
        num_cols = len(data[0]) if num_rows > 0 else 0

        if num_cols < 3:
            return "Error: Need at least 3 columns for X, Y, Z coordinates"

        # Extract X, Y, Z columns
        x_vals = [float(data[i][0]) for i in range(num_rows)]
        y_vals = [float(data[i][1]) for i in range(num_rows)]
        z_vals = [float(data[i][2]) for i in range(num_rows)]

        # Create figure
        fig = plt.figure(figsize=(10, 7))
        ax = fig.add_subplot(111, projection='3d')

        # Create scatter plot
        scatter = ax.scatter(x_vals, y_vals, z_vals, c=z_vals, cmap=color_map, marker=marker, s=50)

        # Set labels
        if title:
            ax.set_title(title)
        if xlabel:
            ax.set_xlabel(xlabel)
        if ylabel:
            ax.set_ylabel(ylabel)
        if zlabel:
            ax.set_zlabel(zlabel)

        # Add legend if requested
        if legend == "true":
            plt.colorbar(scatter, ax=ax, label='Z value')

        # Return based on platform
        if IS_PYODIDE:
            buf = io.BytesIO()
            plt.savefig(buf, format='png', dpi=100, bbox_inches='tight')
            buf.seek(0)
            img_base64 = base64.b64encode(buf.read()).decode('utf-8')
            plt.close(fig)
            return f"data:image/png;base64,{img_base64}"
        else:
            return fig
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Input data (X, Y, Z).
Chart title.
Label for X-axis.
Label for Y-axis.
Label for Z-axis.
Color map for points.
Marker style.
Show legend.

STEM_3D

Create a 3D stem plot.

Excel Usage

=STEM_3D(data, title, xlabel, ylabel, zlabel, stem_threed_orient)
  • data (list[list], required): Input data (X, Y, Z).
  • title (str, optional, default: null): Chart title.
  • xlabel (str, optional, default: null): Label for X-axis.
  • ylabel (str, optional, default: null): Label for Y-axis.
  • zlabel (str, optional, default: null): Label for Z-axis.
  • stem_threed_orient (str, optional, default: “z”): The orientation of the stems.

Returns (object): Matplotlib Figure object (standard Python) or base64 encoded PNG string (Pyodide).

Example 1: Basic 3D stem plot

Inputs:

data
0 0 1
1 0 2
0 1 3
1 1 4

Excel formula:

=STEM_3D({0,0,1;1,0,2;0,1,3;1,1,4})

Expected output:

"chart"

Example 2: 3D stem with labels

Inputs:

data title xlabel ylabel zlabel
0 0 0.5 Stem Plot X Y Z
1 1 1
2 0 0.5

Excel formula:

=STEM_3D({0,0,0.5;1,1,1;2,0,0.5}, "Stem Plot", "X", "Y", "Z")

Expected output:

"chart"

Example 3: Stem plot with X orientation

Inputs:

data stem_threed_orient
1 0 0 x
2 1 0
3 0 1

Excel formula:

=STEM_3D({1,0,0;2,1,0;3,0,1}, "x")

Expected output:

"chart"

Example 4: Simple stem plot

Inputs:

data
0 0 1
1 0 2
0 1 3

Excel formula:

=STEM_3D({0,0,1;1,0,2;0,1,3})

Expected output:

"chart"

Example 5: Multiple stems

Inputs:

data
0 0 1
1 0 2
0 1 3

Excel formula:

=STEM_3D({0,0,1;1,0,2;0,1,3})

Expected output:

"chart"

Example 6: Stem plot with extra labels

Inputs:

data
0 0 1
1 0 2
0 1 3

Excel formula:

=STEM_3D({0,0,1;1,0,2;0,1,3})

Expected output:

"chart"

Python Code

Show Code
import sys
import matplotlib
IS_PYODIDE = sys.platform == "emscripten"
if IS_PYODIDE:
    matplotlib.use('Agg')
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import io
import base64
import numpy as np

def stem_3d(data, title=None, xlabel=None, ylabel=None, zlabel=None, stem_threed_orient='z'):
    """
    Create a 3D stem plot.

    See: https://matplotlib.org/stable/api/_as_gen/mpl_toolkits.mplot3d.axes3d.Axes3D.stem.html

    This example function is provided as-is without any representation of accuracy.

    Args:
        data (list[list]): Input data (X, Y, Z).
        title (str, optional): Chart title. Default is None.
        xlabel (str, optional): Label for X-axis. Default is None.
        ylabel (str, optional): Label for Y-axis. Default is None.
        zlabel (str, optional): Label for Z-axis. Default is None.
        stem_threed_orient (str, optional): The orientation of the stems. Valid options: Z, X, Y. Default is 'z'.

    Returns:
        object: Matplotlib Figure object (standard Python) or base64 encoded PNG string (Pyodide).
    """
    def to2d(x):
        return [[x]] if not isinstance(x, list) else x

    try:
        data = to2d(data)

        if not isinstance(data, list) or not all(isinstance(row, list) for row in data):
            return "Error: Invalid input - data must be a 2D list"

        # Validate dimensions
        num_rows = len(data)
        num_cols = len(data[0]) if num_rows > 0 else 0

        if num_cols < 3:
            return "Error: Need at least 3 columns for X, Y, Z coordinates"

        # Extract and validate columns
        try:
            x_vals = [float(data[i][0]) for i in range(num_rows)]
            y_vals = [float(data[i][1]) for i in range(num_rows)]
            z_vals = [float(data[i][2]) for i in range(num_rows)]
        except (ValueError, TypeError, IndexError):
            return "Error: Input data contains non-numeric values or missing columns"

        # Create figure
        fig = plt.figure(figsize=(10, 7))
        ax = fig.add_subplot(111, projection='3d')

        # Create stem plot
        ax.stem(x_vals, y_vals, z_vals, orientation=stem_threed_orient)

        # Set labels
        if title:
            ax.set_title(title)
        if xlabel:
            ax.set_xlabel(xlabel)
        if ylabel:
            ax.set_ylabel(ylabel)
        if zlabel:
            ax.set_zlabel(zlabel)

        # Return based on platform
        if IS_PYODIDE:
            buf = io.BytesIO()
            plt.savefig(buf, format='png', dpi=100, bbox_inches='tight')
            buf.seek(0)
            img_base64 = base64.b64encode(buf.read()).decode('utf-8')
            plt.close(fig)
            return f"data:image/png;base64,{img_base64}"
        else:
            return fig
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Input data (X, Y, Z).
Chart title.
Label for X-axis.
Label for Y-axis.
Label for Z-axis.
The orientation of the stems.

SURFACE_3D

Create a 3D surface plot.

Excel Usage

=SURFACE_3D(data, title, xlabel, ylabel, zlabel, color_map, colorbar)
  • data (list[list], required): Input Z-data.
  • title (str, optional, default: null): Chart title.
  • xlabel (str, optional, default: null): Label for X-axis.
  • ylabel (str, optional, default: null): Label for Y-axis.
  • zlabel (str, optional, default: null): Label for Z-axis.
  • color_map (str, optional, default: “viridis”): Color map for the surface.
  • colorbar (str, optional, default: “true”): Show colorbar.

Returns (object): Matplotlib Figure object (standard Python) or base64 encoded PNG string (Pyodide).

Example 1: Basic 3D surface plot

Inputs:

data
1 2 3
4 5 6
7 8 9

Excel formula:

=SURFACE_3D({1,2,3;4,5,6;7,8,9})

Expected output:

"chart"

Example 2: Surface with labels and colorbar

Inputs:

data title xlabel ylabel zlabel colorbar
1 4 9 Surface Plot X Y Z true
2 5 10
3 6 11

Excel formula:

=SURFACE_3D({1,4,9;2,5,10;3,6,11}, "Surface Plot", "X", "Y", "Z", "true")

Expected output:

"chart"

Example 3: Using plasma colormap

Inputs:

data color_map
0 1 2 plasma
1 2 3
2 3 4
3 4 5

Excel formula:

=SURFACE_3D({0,1,2;1,2,3;2,3,4;3,4,5}, "plasma")

Expected output:

"chart"

Example 4: Surface without colorbar

Inputs:

data colorbar
5 10 15 false
20 25 30
35 40 45

Excel formula:

=SURFACE_3D({5,10,15;20,25,30;35,40,45}, "false")

Expected output:

"chart"

Python Code

Show Code
import sys
import matplotlib
IS_PYODIDE = sys.platform == "emscripten"
if IS_PYODIDE:
    matplotlib.use('Agg')
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import io
import base64
import numpy as np

def surface_3d(data, title=None, xlabel=None, ylabel=None, zlabel=None, color_map='viridis', colorbar='true'):
    """
    Create a 3D surface plot.

    See: https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.plot_surface.html

    This example function is provided as-is without any representation of accuracy.

    Args:
        data (list[list]): Input Z-data.
        title (str, optional): Chart title. Default is None.
        xlabel (str, optional): Label for X-axis. Default is None.
        ylabel (str, optional): Label for Y-axis. Default is None.
        zlabel (str, optional): Label for Z-axis. Default is None.
        color_map (str, optional): Color map for the surface. Valid options: Viridis, Plasma, Inferno, Magma, Cividis. Default is 'viridis'.
        colorbar (str, optional): Show colorbar. Valid options: True, False. Default is 'true'.

    Returns:
        object: Matplotlib Figure object (standard Python) or base64 encoded PNG string (Pyodide).
    """
    def to2d(x):
        return [[x]] if not isinstance(x, list) else x

    try:
        data = to2d(data)

        if not isinstance(data, list) or not all(isinstance(row, list) for row in data):
            return "Error: Invalid input - data must be a 2D list"

        # Validate and convert to numpy array
        try:
            z_data = np.array(data, dtype=float)
        except (TypeError, ValueError) as e:
            return f"Error: Non-numeric values in data: {str(e)}"

        if z_data.ndim != 2:
            return "Error: Data must be a 2D array"

        if z_data.shape[0] < 2 or z_data.shape[1] < 2:
            return "Error: Surface requires at least 2x2 grid"

        # Create X and Y meshgrid
        rows, cols = z_data.shape
        x_grid = np.arange(cols)
        y_grid = np.arange(rows)
        X, Y = np.meshgrid(x_grid, y_grid)

        # Create figure
        fig = plt.figure(figsize=(10, 7))
        ax = fig.add_subplot(111, projection='3d')

        # Create surface plot
        surf = ax.plot_surface(X, Y, z_data, cmap=color_map, alpha=0.8, edgecolor='none')

        # Set labels
        if title:
            ax.set_title(title)
        if xlabel:
            ax.set_xlabel(xlabel)
        if ylabel:
            ax.set_ylabel(ylabel)
        if zlabel:
            ax.set_zlabel(zlabel)

        # Add colorbar if requested
        if colorbar == "true":
            fig.colorbar(surf, ax=ax, shrink=0.5, aspect=5)

        # Return based on platform
        if IS_PYODIDE:
            buf = io.BytesIO()
            plt.savefig(buf, format='png', dpi=100, bbox_inches='tight')
            buf.seek(0)
            img_base64 = base64.b64encode(buf.read()).decode('utf-8')
            plt.close(fig)
            return f"data:image/png;base64,{img_base64}"
        else:
            return fig
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Input Z-data.
Chart title.
Label for X-axis.
Label for Y-axis.
Label for Z-axis.
Color map for the surface.
Show colorbar.

TRISURF_3D

Create a 3D triangular surface plot.

Excel Usage

=TRISURF_3D(data, title, xlabel, ylabel, zlabel, color_map, legend)
  • data (list[list], required): Input data (X, Y, Z).
  • title (str, optional, default: null): Chart title.
  • xlabel (str, optional, default: null): Label for X-axis.
  • ylabel (str, optional, default: null): Label for Y-axis.
  • zlabel (str, optional, default: null): Label for Z-axis.
  • color_map (str, optional, default: “viridis”): Color map for surface.
  • legend (str, optional, default: “false”): Show legend.

Returns (object): Matplotlib Figure object (standard Python) or base64 encoded PNG string (Pyodide).

Example 1: Basic 3D trisurf plot

Inputs:

data
0 0 1
1 0 2
0 1 3
1 1 4

Excel formula:

=TRISURF_3D({0,0,1;1,0,2;0,1,3;1,1,4})

Expected output:

"chart"

Example 2: 3D trisurf with labels

Inputs:

data title xlabel ylabel zlabel
0 0 1 Triangle Surface X Y Z
2 0 2
0 2 3
2 2 4

Excel formula:

=TRISURF_3D({0,0,1;2,0,2;0,2,3;2,2,4}, "Triangle Surface", "X", "Y", "Z")

Expected output:

"chart"

Example 3: Using plasma colormap

Inputs:

data color_map legend
0 0 1 plasma true
1 1 2
2 0 3
1 -1 4

Excel formula:

=TRISURF_3D({0,0,1;1,1,2;2,0,3;1,-1,4}, "plasma", "true")

Expected output:

"chart"

Example 4: Simple triangular surface

Inputs:

data
0 0 1
1 0 2
0 1 3
1 1 4

Excel formula:

=TRISURF_3D({0,0,1;1,0,2;0,1,3;1,1,4})

Expected output:

"chart"

Example 5: Four points surface

Inputs:

data
0 0 1
1 0 2
0 1 3
1 1 4

Excel formula:

=TRISURF_3D({0,0,1;1,0,2;0,1,3;1,1,4})

Expected output:

"chart"

Example 6: Trisurf with color data

Inputs:

data
0 0 1
1 0 2
0 1 3
1 1 4

Excel formula:

=TRISURF_3D({0,0,1;1,0,2;0,1,3;1,1,4})

Expected output:

"chart"

Python Code

Show Code
import sys
import matplotlib
IS_PYODIDE = sys.platform == "emscripten"
if IS_PYODIDE:
    matplotlib.use('Agg')
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import io
import base64
import numpy as np

def trisurf_3d(data, title=None, xlabel=None, ylabel=None, zlabel=None, color_map='viridis', legend='false'):
    """
    Create a 3D triangular surface plot.

    See: https://matplotlib.org/stable/api/_as_gen/mpl_toolkits.mplot3d.axes3d.Axes3D.plot_trisurf.html

    This example function is provided as-is without any representation of accuracy.

    Args:
        data (list[list]): Input data (X, Y, Z).
        title (str, optional): Chart title. Default is None.
        xlabel (str, optional): Label for X-axis. Default is None.
        ylabel (str, optional): Label for Y-axis. Default is None.
        zlabel (str, optional): Label for Z-axis. Default is None.
        color_map (str, optional): Color map for surface. Valid options: Viridis, Plasma, Inferno, Magma, Cividis. Default is 'viridis'.
        legend (str, optional): Show legend. Valid options: True, False. Default is 'false'.

    Returns:
        object: Matplotlib Figure object (standard Python) or base64 encoded PNG string (Pyodide).
    """
    def to2d(x):
        return [[x]] if not isinstance(x, list) else x

    try:
        data = to2d(data)

        if not isinstance(data, list) or not all(isinstance(row, list) for row in data):
            return "Error: Invalid input - data must be a 2D list"

        # Validate dimensions
        num_rows = len(data)
        num_cols = len(data[0]) if num_rows > 0 else 0

        if num_cols < 3:
            return "Error: Need at least 3 columns for X, Y, Z coordinates"

        # Extract and validate columns
        try:
            x_vals = np.array([float(data[i][0]) for i in range(num_rows)])
            y_vals = np.array([float(data[i][1]) for i in range(num_rows)])
            z_vals = np.array([float(data[i][2]) for i in range(num_rows)])
        except (ValueError, TypeError, IndexError):
            return "Error: Input data contains non-numeric values or missing columns"

        # Create figure
        fig = plt.figure(figsize=(10, 7))
        ax = fig.add_subplot(111, projection='3d')

        # Create trisurf plot
        # Use same logic as existing charts for colormap
        cmap = plt.get_cmap(color_map)
        surf = ax.plot_trisurf(x_vals, y_vals, z_vals, cmap=cmap, linewidth=0.2, antialiased=True)

        # Set labels
        if title:
            ax.set_title(title)
        if xlabel:
            ax.set_xlabel(xlabel)
        if ylabel:
            ax.set_ylabel(ylabel)
        if zlabel:
            ax.set_zlabel(zlabel)

        # Add legend (colorbar) if requested
        if legend == "true":
            fig.colorbar(surf, ax=ax, shrink=0.5, aspect=5, label='Z value')

        # Return based on platform
        if IS_PYODIDE:
            buf = io.BytesIO()
            plt.savefig(buf, format='png', dpi=100, bbox_inches='tight')
            buf.seek(0)
            img_base64 = base64.b64encode(buf.read()).decode('utf-8')
            plt.close(fig)
            return f"data:image/png;base64,{img_base64}"
        else:
            return fig
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Input data (X, Y, Z).
Chart title.
Label for X-axis.
Label for Y-axis.
Label for Z-axis.
Color map for surface.
Show legend.

VOXELS

Create a 3D voxel plot from a 3D grid of values.

Excel Usage

=VOXELS(data, shape, title, edge_color)
  • data (list[list], required): Flattened 3D grid of boolean values (0 or 1).
  • shape (str, required): Shape of the 3D grid as ‘depth,height,width’ (e.g., ‘8,8,8’).
  • title (str, optional, default: null): Chart title.
  • edge_color (str, optional, default: “black”): Color of the voxel edges.

Returns (object): Matplotlib Figure object (standard Python) or base64 encoded PNG string (Pyodide).

Example 1: Simple 3x3x3 cube corners

Inputs:

data shape title
1 0 0 3,1,3 Voxel Corners
0 0 0
0 0 1

Excel formula:

=VOXELS({1,0,0;0,0,0;0,0,1}, "3,1,3", "Voxel Corners")

Expected output:

"chart"

Example 2: Single voxel

Inputs:

data shape
1 1,1,1

Excel formula:

=VOXELS({1}, "1,1,1")

Expected output:

"chart"

Example 3: Voxels with gray edges

Inputs:

data shape edge_color
1 1 2,1,2 gray
1 1

Excel formula:

=VOXELS({1,1;1,1}, "2,1,2", "gray")

Expected output:

"chart"

Example 4: Voxels without edges

Inputs:

data shape edge_color
1 0 2,1,2 none
0 1

Excel formula:

=VOXELS({1,0;0,1}, "2,1,2", "none")

Expected output:

"chart"

Python Code

Show Code
import sys
import matplotlib
IS_PYODIDE = sys.platform == "emscripten"
if IS_PYODIDE:
    matplotlib.use('Agg')
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import io
import base64
import numpy as np

def voxels(data, shape, title=None, edge_color='black'):
    """
    Create a 3D voxel plot from a 3D grid of values.

    See: https://matplotlib.org/stable/api/_as_gen/mpl_toolkits.mplot3d.axes3d.Axes3D.voxels.html

    This example function is provided as-is without any representation of accuracy.

    Args:
        data (list[list]): Flattened 3D grid of boolean values (0 or 1).
        shape (str): Shape of the 3D grid as 'depth,height,width' (e.g., '8,8,8').
        title (str, optional): Chart title. Default is None.
        edge_color (str, optional): Color of the voxel edges. Valid options: Black, Gray, White, None. Default is 'black'.

    Returns:
        object: Matplotlib Figure object (standard Python) or base64 encoded PNG string (Pyodide).
    """
    def to2d(x):
        return [[x]] if not isinstance(x, list) else x

    try:
        data = to2d(data)
        if not isinstance(data, list) or not data or not isinstance(data[0], list):
            return "Error: Input data must be a 2D list (flattened grid)."

        # Prepare boolean array
        flat = []
        for row in data:
            for x in row:
                try:
                    if x is None or x == "":
                        flat.append(False)
                    else:
                        flat.append(bool(float(x)))
                except (TypeError, ValueError):
                    flat.append(False)

        # Parse shape
        try:
            d, h, w = map(int, shape.split(','))
        except Exception:
            return "Error: Invalid shape format. Use 'depth,height,width' (e.g., '8,8,8')."

        if len(flat) < d * h * w:
            return f"Error: Input data size ({len(flat)}) is smaller than requested shape {shape} ({d*h*w})."

        # Reshape
        voxel_array = np.array(flat[:d*h*w]).reshape((d, h, w))

        # Create figure with 3D projection
        fig, ax = plt.subplots(figsize=(10, 7), subplot_kw={"projection": "3d"})

        # Plot voxels
        ax.voxels(voxel_array, edgecolor=edge_color if edge_color != "none" else None)

        # Set title
        if title:
            ax.set_title(title)

        # Remove ticks for gallery style
        ax.set(xticklabels=[], yticklabels=[], zticklabels=[])

        plt.tight_layout()

        if IS_PYODIDE:
            buf = io.BytesIO()
            plt.savefig(buf, format='png', dpi=100, bbox_inches='tight')
            plt.close(fig)
            buf.seek(0)
            img_bytes = buf.read()
            img_b64 = base64.b64encode(img_bytes).decode('utf-8')
            return f"data:image/png;base64,{img_b64}"
        else:
            return fig
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Flattened 3D grid of boolean values (0 or 1).
Shape of the 3D grid as 'depth,height,width' (e.g., '8,8,8').
Chart title.
Color of the voxel edges.

WIREFRAME_3D

Create a 3D wireframe plot.

Excel Usage

=WIREFRAME_3D(data, title, xlabel, ylabel, zlabel, plot_color, rstride, cstride, legend)
  • data (list[list], required): Input Z-data.
  • title (str, optional, default: null): Chart title.
  • xlabel (str, optional, default: null): Label for X-axis.
  • ylabel (str, optional, default: null): Label for Y-axis.
  • zlabel (str, optional, default: null): Label for Z-axis.
  • plot_color (str, optional, default: “blue”): Wireframe color.
  • rstride (int, optional, default: 1): Row stride.
  • cstride (int, optional, default: 1): Column stride.
  • legend (str, optional, default: “false”): Show legend.

Returns (object): Matplotlib Figure object (standard Python) or base64 encoded PNG string (Pyodide).

Example 1: Basic 3D wireframe plot

Inputs:

data
1 2 3
4 5 6
7 8 9

Excel formula:

=WIREFRAME_3D({1,2,3;4,5,6;7,8,9})

Expected output:

"chart"

Example 2: Wireframe with labels

Inputs:

data title xlabel ylabel zlabel
1 4 9 Wireframe Plot X Y Z
2 5 10
3 6 11

Excel formula:

=WIREFRAME_3D({1,4,9;2,5,10;3,6,11}, "Wireframe Plot", "X", "Y", "Z")

Expected output:

"chart"

Example 3: Using stride parameters

Inputs:

data rstride cstride
1 2 3 4 1 1
5 6 7 8
9 10 11 12
13 14 15 16

Excel formula:

=WIREFRAME_3D({1,2,3,4;5,6,7,8;9,10,11,12;13,14,15,16}, 1, 1)

Expected output:

"chart"

Example 4: Black wireframe with legend

Inputs:

data plot_color legend
0 1 2 black true
3 4 5
6 7 8

Excel formula:

=WIREFRAME_3D({0,1,2;3,4,5;6,7,8}, "black", "true")

Expected output:

"chart"

Python Code

Show Code
import sys
import matplotlib
IS_PYODIDE = sys.platform == "emscripten"
if IS_PYODIDE:
    matplotlib.use('Agg')
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import io
import base64
import numpy as np

def wireframe_3d(data, title=None, xlabel=None, ylabel=None, zlabel=None, plot_color='blue', rstride=1, cstride=1, legend='false'):
    """
    Create a 3D wireframe plot.

    See: https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.plot_wireframe.html

    This example function is provided as-is without any representation of accuracy.

    Args:
        data (list[list]): Input Z-data.
        title (str, optional): Chart title. Default is None.
        xlabel (str, optional): Label for X-axis. Default is None.
        ylabel (str, optional): Label for Y-axis. Default is None.
        zlabel (str, optional): Label for Z-axis. Default is None.
        plot_color (str, optional): Wireframe color. Valid options: Blue, Green, Red, Cyan, Magenta, Yellow, Black, White. Default is 'blue'.
        rstride (int, optional): Row stride. Default is 1.
        cstride (int, optional): Column stride. Default is 1.
        legend (str, optional): Show legend. Valid options: True, False. Default is 'false'.

    Returns:
        object: Matplotlib Figure object (standard Python) or base64 encoded PNG string (Pyodide).
    """
    def to2d(x):
        return [[x]] if not isinstance(x, list) else x

    try:
        data = to2d(data)

        if not isinstance(data, list) or not all(isinstance(row, list) for row in data):
            return "Error: Invalid input - data must be a 2D list"

        # Validate and convert to numpy array
        try:
            z_data = np.array(data, dtype=float)
        except (TypeError, ValueError) as e:
            return f"Error: Non-numeric values in data: {str(e)}"

        if z_data.ndim != 2:
            return "Error: Data must be a 2D array"

        if z_data.shape[0] < 2 or z_data.shape[1] < 2:
            return "Error: Wireframe requires at least 2x2 grid"

        # Create X and Y meshgrid
        rows, cols = z_data.shape
        x_grid = np.arange(cols)
        y_grid = np.arange(rows)
        X, Y = np.meshgrid(x_grid, y_grid)

        # Create figure
        fig = plt.figure(figsize=(10, 7))
        ax = fig.add_subplot(111, projection='3d')

        # Create wireframe plot
        ax.plot_wireframe(X, Y, z_data, color=plot_color, rstride=rstride, cstride=cstride, linewidth=1)

        # Set labels
        if title:
            ax.set_title(title)
        if xlabel:
            ax.set_xlabel(xlabel)
        if ylabel:
            ax.set_ylabel(ylabel)
        if zlabel:
            ax.set_zlabel(zlabel)

        # Add legend if requested
        if legend == "true":
            ax.legend(['Wireframe'])

        # Return based on platform
        if IS_PYODIDE:
            buf = io.BytesIO()
            plt.savefig(buf, format='png', dpi=100, bbox_inches='tight')
            buf.seek(0)
            img_base64 = base64.b64encode(buf.read()).decode('utf-8')
            plt.close(fig)
            return f"data:image/png;base64,{img_base64}"
        else:
            return fig
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Input Z-data.
Chart title.
Label for X-axis.
Label for Y-axis.
Label for Z-axis.
Wireframe color.
Row stride.
Column stride.
Show legend.