QUIVER_3D

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

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.