Skip to content

Commit

Permalink
Figure.ternary: Add parameters alabel, blabel, and clabel (#2139)
Browse files Browse the repository at this point in the history
Co-authored-by: Dongdong Tian <[email protected]>
Co-authored-by: actions-bot <[email protected]>
  • Loading branch information
3 people authored Oct 5, 2022
1 parent f7b0e3f commit 42208f0
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
17 changes: 16 additions & 1 deletion pygmt/src/ternary.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
t="transparency",
)
@kwargs_to_strings(R="sequence", c="sequence_comma", p="sequence")
def ternary(self, data, **kwargs):
def ternary(self, data, alabel=None, blabel=None, clabel=None, **kwargs):
r"""
Reads (*a*,\ *b*,\ *c*\ [,\ *z*]) records from *data* and plots symbols at
those locations on a ternary diagram. If a symbol is selected and no symbol
Expand Down Expand Up @@ -54,6 +54,14 @@ def ternary(self, data, **kwargs):
and **c**.
{cmap}
{fill}
alabel : str
Set the label for the *a* vertex where the component is 100%. The
label is placed at a distance of three times the
:gmt-term:`MAP_LABEL_OFFSET` setting from the corner.
blabel : str
Set the label for the *b* vertex where the component is 100%.
clabel : str
Set the label for the *c* vertex where the component is 100%.
style : str
*symbol*\[\ *size*].
Plot individual symbols in a ternary diagram.
Expand All @@ -66,6 +74,13 @@ def ternary(self, data, **kwargs):
{transparency}
"""
kwargs = self._preprocess(**kwargs) # pylint: disable=protected-access

if alabel or blabel or clabel:
alabel = str(alabel) if alabel is not None else "-"
blabel = str(blabel) if blabel is not None else "-"
clabel = str(clabel) if clabel is not None else "-"
kwargs["L"] = "/".join([alabel, blabel, clabel])

with Session() as lib:
file_context = lib.virtualfile_from_data(check_kind="vector", data=data)
with file_context as infile:
Expand Down
4 changes: 4 additions & 0 deletions pygmt/tests/baseline/test_ternary_1_label.png.dvc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: 7278b6cdaf0076840927380a22d03846
size: 63228
path: test_ternary_1_label.png
4 changes: 4 additions & 0 deletions pygmt/tests/baseline/test_ternary_3_labels.png.dvc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: e303384766b3b5e31cad90a9b5e61136
size: 64570
path: test_ternary_3_labels.png
40 changes: 40 additions & 0 deletions pygmt/tests/test_ternary.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,43 @@ def test_ternary(array):
pen="thinnest",
)
return fig


@pytest.mark.mpl_image_compare
def test_ternary_3_labels(array):
"""
Test plotting a ternary chart with 3 labels.
"""
fig = Figure()
fig.ternary(
data=array,
region=[0, 100, 0, 100, 0, 100],
cmap="red,orange,yellow,green,blue,violet",
width="10c",
alabel="A",
blabel="B",
clabel="C",
frame=["bafg+lAir", "cafg+lLimestone", "aafg+lWater"],
style="c0.1c",
pen="thinnest",
)
return fig


@pytest.mark.mpl_image_compare
def test_ternary_1_label(array):
"""
Test plotting a ternary chart with 1 label.
"""
fig = Figure()
fig.ternary(
data=array,
region=[0, 100, 0, 100, 0, 100],
cmap="red,orange,yellow,green,blue,violet",
width="10c",
alabel="A",
frame=["bafg+lAir", "cafg+lLimestone", "aafg+lWater"],
style="c0.1c",
pen="thinnest",
)
return fig

0 comments on commit 42208f0

Please sign in to comment.