Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Figure.ternary: Add parameters alabel, blabel, and clabel #2139

Merged
merged 16 commits into from
Oct 5, 2022
Merged
Binary file added baseline/test_ternary.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added baseline/test_ternary_1_label.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added baseline/test_ternary_3_labels.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 15 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,12 @@ def ternary(self, data, **kwargs):
{transparency}
"""
kwargs = self._preprocess(**kwargs) # pylint: disable=protected-access

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])
michaelgrund marked this conversation as resolved.
Show resolved Hide resolved

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