Ternary plots are powerful tools for visualizing three-component mixtures bound by a constant sum of 100%. In technical diving, life-support operations, and hyperbaric engineering, these plots take the form of Trimix Triangles. They map varying proportions of oxygen (O2), nitrogen (N2), and helium (He) into a single 2D visual field, isolating physiological safety windows for target depths.
While generic charts exist, custom plots allow gas blenders and dive plan supervisors to overlay specific operational parameters—such as strict Maximum Operating Depth (MOD) limits, custom Equivalent Narcotic Depths (END), and exact gas blending trajectories.
Using modern tools like Python, Matplotlib, and Plotly, you can construct custom Trimixtriangles tailored to your exact operational parameters.
A custom ternary plot displaying safe breathable gas boundaries. Source: ResearchGate
1. Prerequisites and Mathematical Setup
Before writing any code, we must establish the geometric coordinate system. Ternary plots map three fractions (FO2,FN2,FHe) where FO2+FN2+FHe=1.0.
To render this system on standard Cartesian screen space (x,y), we map the three pure gas states to the vertices of an equilateral triangle:
- Oxygen Vertex (100% O2): Located at (0,0)
- Nitrogen Vertex (100% N2): Located at (1,0)
- Helium Vertex (100% He): Located at (0.5,23
≈0.866)
Coordinate Transformation Formulas
To transform any ternary gas ratio into 2D Cartesian space, use the following transformation equations:
x=FN2+21FHe
y=23FHe
These formulas serve as the engine for rendering background grid lines, physiological boundary lines, and individual data points.
2. Step-by-Step Python Guide using Matplotlib and mpltern
The easiest way to generate custom ternary plots programmatically in Python is by utilizing the mpltern library, which extends Matplotlib to handle triangular coordinate systems directly.
1
Environment Setup
Install required Python packages
1.Environment Setup:Install required Python packages.
Open your terminal or notebook environment and install the necessary visualization modules:
Bash
pip install matplotlib mpltern numpy pandas
2
Initialize the Ternary Axis
Define the triangular layout and labels
2.Initialize the Ternary Axis:Define the triangular layout and labels.
Import the libraries and create a canvas with three designated axes corresponding to Helium, Oxygen, and Nitrogen:
Python
import matplotlib.pyplot as plt
import mpltern
import numpy as np
# Create figure and ternary projection
fig = plt.figure(figsize=(8, 7))
ax = fig.add_subplot(projection='ternary')
# Set labels for vertices
ax.set_tlabel('Helium ($He$) %') # Top vertex
ax.set_llabel('Oxygen ($O_2$) %') # Left vertex
ax.set_rlabel('Nitrogen ($N_2$) %') # Right vertex
3
Plot Physiological Boundaries
Add MOD and END cutoff lines
3.Plot Physiological Boundaries:Add MOD and END cutoff lines.
Calculate boundary lines for a sample 60-meter (200-foot) dive where maximum ppO2=1.4 bar and target END=30 meters:
Python
# Define maximum oxygen fraction line (FO2 <= 0.20 for 60m)
# Define minimum helium fraction line for END constraint
he_range = np.linspace(0, 100, 100)
o2_limit = 20 # Max 20% O2 at 7.0 ATA for 1.4 bar ppO2
# Plot constraint lines (Top, Left, Right format)
# Shading the acceptable breathable zone
ax.axline(te=(0, o2_limit, 100-o2_limit),
rlabel="MOD Limit (1.4 bar)",
color='red', linestyle='--')
4
Overlay Standard Gas Points
Mark key technical blends
4.Overlay Standard Gas Points:Mark key technical blends.
Plot discrete gas coordinate points onto the canvas to visually contextualize common technical diving blends:
Python
# Gases defined as (Helium, Oxygen, Nitrogen)
gases = {
"Tx 21/35": (35, 21, 44),
"Tx 18/45": (45, 18, 37),
"Tx 15/55": (55, 15, 30),
"Tx 10/70": (70, 10, 20)
}
for name, (he, o2, n2) in gases.items():
ax.scatter(he, o2, n2, label=name, s=60)
ax.text(he+1, o2+1, n2-2, name, fontsize=9)
ax.legend(loc='upper right')
plt.title("Custom Trimix Chart for 60m Planning")
plt.show()
3. Designing Interactive Visualizations with Plotly
For web applications, digital dive planning software, or interactive blenders’ dashboards, static images are often insufficient. Using plotly.express, you can create interactive charts featuring hover tooltips, dynamic zooming, and clickable data points.
Python
import plotly.express as px
import pandas as pd
# Prepare dataframe of standard blends
data = pd.DataFrame([
{"Name": "Air", "O2": 21, "He": 0, "N2": 79, "Type": "Recreational"},
{"Name": "Nitrox 32", "O2": 32, "He": 0, "N2": 68, "Type": "Nitrox"},
{"Name": "Trimix 21/35", "O2": 21, "He": 35, "N2": 44, "Type": "Normoxic Trimix"},
{"Name": "Trimix 18/45", "O2": 18, "He": 45, "N2": 37, "Type": "Normoxic Trimix"},
{"Name": "Trimix 10/70", "O2": 10, "He": 70, "N2": 20, "Type": "Hypoxic Trimix"},
])
# Create interactive ternary scatter plot
fig = px.scatter_ternary(
data,
a="He", b="O2", c="N2",
hover_name="Name",
color="Type",
size_max=15,
title="Interactive Trimix Gas Chart"
)
fig.show()
4. Key Customization Features to Add
When publishing custom charts for technical teams, consider building in these additional features:
| Custom Element | Purpose | Implementation Method |
|---|---|---|
| Hypoxic Zone Shading | Highlights regions with <18% O2 requiring travel gas | Polygon fill where FO2<0.18 |
| Gas Density Contours | Displays density lines exceeding 5.2 g/L | Isopleth overlay using ideal gas equations |
| Blending Trajectory Vectors | Shows mixing paths when topping off cylinders | Vector lines connecting (x1,y1)→(x2,y2) |
| Color-Coded Depth Bands | Groups gas mixes by target depth suitability | Shaded background polygons |
Gas blending charts provide critical data for plot customization. Source: PADI IDC Exam Revision and Theory
5. Practical Guidelines for Accurate Plotting
- Standardize Orientation: Always maintain He at the top apex, O2 at the bottom-left vertex, and N2 at the bottom-right vertex. Reversing vertices leads to severe operational errors.
- Double-Check Normalization: Ensure input datasets sum to exactly 100%. When plotting real-world analyzer outputs, minor sensor variance (18.1% O2+44.8% He+37.0% N2=99.9%) must be normalized before converting coordinates.
- Include High-Contrast Grid Lines: Place grid lines at 10% increments to ensure chart readers can manually verify coordinates without relying exclusively on digital tools.
Conclusion: Tailoring Visuals to Specific Diving Logistics
Creating custom ternary plots transforms complex multi-gas mathematics into actionable visual tools. By following this step-by-step programming approach, you can build static or interactive diagrams tailored precisely to your team’s depth profiles, safety guidelines, and gas blending capabilities.