WIREFRAME_3D
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).
Examples
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
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)}"