Skip to content

Commit 73e178d

Browse files
authored
Figure.ternary: Improve the handling of the alabel/blabel/clabel parameters (#3382)
1 parent 819bac1 commit 73e178d

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

pygmt/src/ternary.py

+20-14
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,14 @@
2323
t="transparency",
2424
)
2525
@kwargs_to_strings(R="sequence", c="sequence_comma", p="sequence")
26-
def ternary(self, data, alabel=None, blabel=None, clabel=None, **kwargs):
26+
def ternary(
27+
self,
28+
data,
29+
alabel: str | None = None,
30+
blabel: str | None = None,
31+
clabel: str | None = None,
32+
**kwargs,
33+
):
2734
r"""
2835
Plot ternary diagrams.
2936
@@ -56,14 +63,14 @@ def ternary(self, data, alabel=None, blabel=None, clabel=None, **kwargs):
5663
and **c**.
5764
{cmap}
5865
{fill}
59-
alabel : str
60-
Set the label for the *a* vertex where the component is 100%. The
61-
label is placed at a distance of three times the
62-
:gmt-term:`MAP_LABEL_OFFSET` setting from the corner.
63-
blabel : str
64-
Set the label for the *b* vertex where the component is 100%.
65-
clabel : str
66-
Set the label for the *c* vertex where the component is 100%.
66+
alabel
67+
Set the label for the *a* vertex where the component is 100%. The label is
68+
placed at a distance of three times the :gmt-term:`MAP_LABEL_OFFSET` setting
69+
from the corner.
70+
blabel
71+
Same as ``alabel`` but for the *b* vertex.
72+
clabel
73+
Same as ``alabel`` but for the *c* vertex.
6774
style : str
6875
*symbol*\[\ *size*].
6976
Plot individual symbols in a ternary diagram.
@@ -75,11 +82,10 @@ def ternary(self, data, alabel=None, blabel=None, clabel=None, **kwargs):
7582
"""
7683
kwargs = self._preprocess(**kwargs)
7784

78-
if alabel or blabel or clabel:
79-
alabel = str(alabel) if alabel is not None else "-"
80-
blabel = str(blabel) if blabel is not None else "-"
81-
clabel = str(clabel) if clabel is not None else "-"
82-
kwargs["L"] = f"{alabel}/{blabel}/{clabel}"
85+
# -Lalabel/blabel/clabel. '-' means skipping the label.
86+
labels = (alabel, blabel, clabel)
87+
if any(v is not None for v in labels):
88+
kwargs["L"] = "/".join(str(v) if v is not None else "-" for v in labels)
8389

8490
# Patch for GMT < 6.5.0.
8591
# See https://github.com/GenericMappingTools/pygmt/pull/2138

0 commit comments

Comments
 (0)