Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
8ab177e
add ternary frame
Chuan1937 Apr 9, 2026
7744978
Internally convert xaxis/yaxis/zaxis to -Ba/-Bb/-Bc
Chuan1937 Apr 9, 2026
c9eb74d
Merge branch 'main' into test_ternary
Chuan1937 Apr 9, 2026
1e49df0
Revert test_ternary.py changes to split into two PRs
Chuan1937 Apr 10, 2026
c1056a4
Merge branch 'main' into test_ternary
Chuan1937 Apr 10, 2026
26a8c43
fix mypy check
Chuan1937 Apr 10, 2026
a186dde
Internally convert xaxis/yaxis/zaxis to -Ba/-Bb/-Bc for ternary
Chuan1937 Apr 10, 2026
098ea9b
internal function
Chuan1937 Apr 10, 2026
4732e16
Merge branch 'main' into test_ternary
Chuan1937 Apr 10, 2026
077fcba
Merge branch 'test_ternary' of github.com:GenericMappingTools/pygmt i…
Chuan1937 Apr 10, 2026
6924d9f
private function
Chuan1937 Apr 10, 2026
a353399
format check
Chuan1937 Apr 10, 2026
9a98469
use dataclass
Chuan1937 Apr 15, 2026
71584a0
check
Chuan1937 Apr 15, 2026
e01f5a5
Update pygmt/src/ternary.py
Chuan1937 Apr 16, 2026
843a112
Update pygmt/src/ternary.py
Chuan1937 Apr 16, 2026
4b1770b
Merge branch 'main' into test_ternary
Chuan1937 Apr 16, 2026
43700a8
fix check
Chuan1937 Apr 16, 2026
358679b
use alias
Chuan1937 Apr 16, 2026
3c53887
fix failure
Chuan1937 Apr 16, 2026
4abc67c
Update pygmt/src/ternary.py
Chuan1937 Apr 16, 2026
9bdbb7e
fix
Chuan1937 Apr 16, 2026
6015793
Update pygmt/src/ternary.py
Chuan1937 Apr 17, 2026
c956f54
Update pygmt/src/ternary.py
Chuan1937 Apr 17, 2026
461b408
Update pygmt/src/ternary.py
Chuan1937 Apr 17, 2026
7d96092
Update pygmt/src/ternary.py
Chuan1937 Apr 17, 2026
cce2532
Update pygmt/src/ternary.py
Chuan1937 Apr 17, 2026
8834278
Update pygmt/src/ternary.py
Chuan1937 Apr 17, 2026
3372921
Update pygmt/src/ternary.py
Chuan1937 Apr 17, 2026
c131e37
Update pygmt/src/ternary.py
Chuan1937 Apr 17, 2026
eb0288a
Update pygmt/src/ternary.py
Chuan1937 Apr 17, 2026
c06fa85
Update pygmt/src/ternary.py
Chuan1937 Apr 17, 2026
4d52917
Update pygmt/src/ternary.py
Chuan1937 Apr 17, 2026
7b29bdd
add format,docstring,test
Chuan1937 Apr 17, 2026
60dc5c3
Update pygmt/tests/test_ternary.py
Chuan1937 Apr 17, 2026
9016020
Update pygmt/tests/test_ternary.py
Chuan1937 Apr 17, 2026
a2f2562
fix format
Chuan1937 Apr 17, 2026
1b8a3a9
Add baseline images for ternary tests and fix missing return fig
Chuan1937 Apr 17, 2026
37bda2b
Update pygmt/src/ternary.py
Chuan1937 Apr 17, 2026
d989ab5
Restore original baseline images
Chuan1937 Apr 17, 2026
3ce18b5
Fix ternary frame border handling for string/Axis inputs
Chuan1937 Apr 19, 2026
f5ae2ac
fix docs
Chuan1937 Apr 19, 2026
6b69c2c
Merge branch 'main' into test_ternary
Chuan1937 Apr 19, 2026
247e0b0
update test_ternary.py
Chuan1937 Apr 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion pygmt/src/ternary.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
from pygmt._typing import PathLike, TableLike
from pygmt.alias import Alias, AliasSystem
from pygmt.clib import Session
from pygmt.exceptions import GMTParameterError
from pygmt.helpers import build_arg_list, fmt_docstring, use_alias
from pygmt.params import Axis, Frame


@fmt_docstring
Expand All @@ -20,7 +22,7 @@ def ternary( # noqa: PLR0913
blabel: str | None = None,
clabel: str | None = None,
region: Sequence[float | str] | str | None = None,
frame: str | Sequence[str] | Literal["none"] | bool = False,
frame: str | Sequence[str] | Literal["none"] | bool | Frame | Axis = False,
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
| bool = False,
panel: int | Sequence[int] | bool = False,
Comment thread
Chuan1937 marked this conversation as resolved.
Expand Down Expand Up @@ -90,6 +92,43 @@ def ternary( # noqa: PLR0913
_labels = [v if v is not None else "-" for v in (alabel, blabel, clabel)]
labels = _labels if any(v != "-" for v in _labels) else None

# Convert Frame/Axis to ternary-compatible format.
Comment thread
Chuan1937 marked this conversation as resolved.
Outdated
# For ternary diagrams, axis names are a, b, c (not x, y, z), there are no
# primary/secondary axes, and frame sides (e.g., "WSen") are not supported.
if isinstance(frame, Axis):
frame = str(frame)
elif isinstance(frame, Frame):
if frame.axes:
raise GMTParameterError(
conflicts_with=("frame", ["frame.axes"]),
reason="For ternary diagrams, Frame.axes (e.g., 'WSen') is not supported.",
)
if any((frame.xaxis2, frame.yaxis2, frame.zaxis2)):
raise GMTParameterError(
conflicts_with=(
"frame",
["frame.xaxis2", "frame.yaxis2", "frame.zaxis2"],
),
reason="For ternary diagrams, secondary axes are not supported.",
)

parts = []

if frame.title:
parts.append(f"+t{frame.title}")
# Uniform axis setting (applies to all three ternary axes)
if frame.axis:
parts.append(str(frame.axis))
# Per-axis: xaxis→a, yaxis→b, zaxis→c
for ternary_prefix, axis_obj in [
("a", frame.xaxis),
("b", frame.yaxis),
("c", frame.zaxis),
]:
if axis_obj:
parts.append(f"{ternary_prefix}{axis_obj}")
frame = parts

aliasdict = AliasSystem(
L=Alias(labels, name="alabel/blabel/clabel", sep="/", size=3),
).add_common(
Expand Down
66 changes: 63 additions & 3 deletions pygmt/tests/test_ternary.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import numpy as np
import pytest
from pygmt import Figure
from pygmt.exceptions import GMTParameterError
from pygmt.params import Axis, Frame


@pytest.fixture(scope="module", name="array")
Expand Down Expand Up @@ -58,7 +60,11 @@ def test_ternary(array):
region=[0, 100, 0, 100, 0, 100],
cmap="red,orange,yellow,green,blue,violet",
width="10c",
frame=["bafg+lAir", "cafg+lLimestone", "aafg+lWater"],
frame=Frame(
xaxis=Axis(annot=True, tick=True, grid=True, label="Water"),
yaxis=Axis(annot=True, tick=True, grid=True, label="Air"),
zaxis=Axis(annot=True, tick=True, grid=True, label="Limestone"),
),
style="c0.1c",
pen="thinnest",
)
Expand All @@ -80,7 +86,11 @@ def test_ternary_3_labels(array):
alabel="A",
blabel="B",
clabel="C",
frame=["bafg+lAir", "cafg+lLimestone", "aafg+lWater"],
frame=Frame(
xaxis=Axis(annot=True, tick=True, grid=True, label="Water"),
yaxis=Axis(annot=True, tick=True, grid=True, label="Air"),
zaxis=Axis(annot=True, tick=True, grid=True, label="Limestone"),
),
style="c0.1c",
pen="thinnest",
)
Expand All @@ -99,8 +109,58 @@ def test_ternary_1_label(array):
cmap="red,orange,yellow,green,blue,violet",
width="10c",
alabel="A",
frame=["bafg+lAir", "cafg+lLimestone", "aafg+lWater"],
frame=Frame(
xaxis=Axis(annot=True, tick=True, grid=True, label="Water"),
yaxis=Axis(annot=True, tick=True, grid=True, label="Air"),
zaxis=Axis(annot=True, tick=True, grid=True, label="Limestone"),
),
style="c0.1c",
pen="thinnest",
)
return fig


Comment thread
Chuan1937 marked this conversation as resolved.
def test_ternary_axis(array):
Comment thread
Chuan1937 marked this conversation as resolved.
Outdated
"""
Test plotting a ternary chart with Axis object for frame.
"""
fig = Figure()
fig.ternary(
data=array,
region=[0, 100, 0, 100, 0, 100],
cmap="red,orange,yellow,green,blue,violet",
width="10c",
frame=Axis(annot=True, tick=True, grid=True),
style="c0.1c",
pen="thinnest",
)


Comment thread
Chuan1937 marked this conversation as resolved.
Outdated
def test_ternary_frame_axes_not_supported(array):
"""
Test that Frame.axes is rejected for ternary diagrams.
"""
fig = Figure()
with pytest.raises(GMTParameterError, match=r"Frame\.axes"):
fig.ternary(
data=array,
region=[0, 100, 0, 100, 0, 100],
width="10c",
frame=Frame(axes="WSen", axis=Axis(annot=True)),
style="c0.1c",
)


def test_ternary_frame_secondary_axes_not_supported(array):
"""
Test that secondary axes are rejected for ternary diagrams.
"""
fig = Figure()
with pytest.raises(GMTParameterError, match="secondary axes"):
fig.ternary(
data=array,
region=[0, 100, 0, 100, 0, 100],
width="10c",
frame=Frame(xaxis2=Axis(annot=True)),
style="c0.1c",
)
Comment thread
Chuan1937 marked this conversation as resolved.
Outdated
Loading