TRIPLOT
Excel Usage
=TRIPLOT(data, title, xlabel, ylabel, line_color, marker)
data(list[list], required): Input data with 2 columns (X, Y).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.line_color(str, optional, default: “blue”): Color of the grid lines.marker(str, optional, default: “none”): Marker style for points.
Returns (object): Matplotlib Figure object (standard Python) or base64 encoded PNG string (Pyodide).
Example 1: Simple triangular grid lines
Inputs:
| data | title | |
|---|---|---|
| 0 | 0 | Triangular Grid |
| 1 | 0 | |
| 0 | 1 | |
| 1 | 1 | |
| 0.5 | 0.5 |
Excel formula:
=TRIPLOT({0,0;1,0;0,1;1,1;0.5,0.5}, "Triangular Grid")
Expected output:
"chart"
Example 2: Grid lines with markers
Inputs:
| data | marker | line_color | |
|---|---|---|---|
| 0 | 0 | o | red |
| 1 | 0 | ||
| 0.5 | 0.866 |
Excel formula:
=TRIPLOT({0,0;1,0;0.5,0.866}, "o", "red")
Expected output:
"chart"
Example 3: Grid lines with square markers
Inputs:
| data | marker | line_color | |
|---|---|---|---|
| 0 | 0 | s | green |
| 2 | 0 | ||
| 1 | 2 |
Excel formula:
=TRIPLOT({0,0;2,0;1,2}, "s", "green")
Expected output:
"chart"
Example 4: Simple black grid lines
Inputs:
| data | line_color | |
|---|---|---|
| 0 | 0 | black |
| 1 | 1 | |
| 1 | 0 |
Excel formula:
=TRIPLOT({0,0;1,1;1,0}, "black")
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
import io
import base64
import numpy as np
def triplot(data, title=None, xlabel=None, ylabel=None, line_color='blue', marker='none'):
"""
Draw an unstructured triangular grid as lines and/or markers.
See: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.triplot.html
This example function is provided as-is without any representation of accuracy.
Args:
data (list[list]): Input data with 2 columns (X, Y).
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.
line_color (str, optional): Color of the grid lines. Valid options: Blue, Green, Red, Black. Default is 'blue'.
marker (str, optional): Marker style for points. Valid options: None, Point, Pixel, Circle, Square, Triangle Down, Triangle Up. Default is 'none'.
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."
# Convert to numpy array
try:
arr = np.array(data, dtype=float)
except Exception:
return "Error: Data must be numeric."
if arr.shape[1] < 2:
return "Error: Data must have at least 2 columns (X, Y)."
# Extract coordinates
x, y = arr[:, 0], arr[:, 1]
# Create figure
fig, ax = plt.subplots(figsize=(8, 6))
# Plot triplot
ax.triplot(x, y, color=line_color, marker=marker if marker else None)
# Set labels and title
if title:
ax.set_title(title)
if xlabel:
ax.set_xlabel(xlabel)
if ylabel:
ax.set_ylabel(ylabel)
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
Input data with 2 columns (X, Y).
Chart title.
Label for X-axis.
Label for Y-axis.
Color of the grid lines.
Marker style for points.