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

Wrap ternary #1431

Merged
merged 33 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
b0d2901
add ternary.py
willschlitzer Aug 10, 2021
601b89a
update ternary import statements
willschlitzer Aug 10, 2021
1333d6a
Merge branch 'main' into wrap-ternary
willschlitzer Dec 15, 2021
0ff0b8c
Merge branch 'main' into wrap-ternary
willschlitzer Dec 17, 2021
539961c
add test_ternary.py
willschlitzer Dec 17, 2021
2982a39
fix test name in test_ternary.py
willschlitzer Dec 17, 2021
6d454d8
add ternary dvc
willschlitzer Dec 17, 2021
28b16a9
run make format
willschlitzer Dec 19, 2021
0130355
Apply suggestions from code review
willschlitzer Dec 26, 2021
59bd4fc
add ternary to index.rst
willschlitzer Dec 26, 2021
2ad07f2
fix failing test
willschlitzer Dec 26, 2021
fff77f1
update test_ternary() to avoid using makecpt
willschlitzer Dec 26, 2021
5324d26
remove unused import
willschlitzer Dec 26, 2021
331a89a
Apply suggestions from code review
willschlitzer Jan 3, 2022
33d4cb0
update test_ternary.png.dvc
willschlitzer Jan 3, 2022
c750705
rename "projection" to "width" in ternary.py
willschlitzer Jan 3, 2022
0ea1ea9
update test in test_ternary.py
willschlitzer Jan 3, 2022
ce6de7c
change "table" to "data"
willschlitzer Jan 4, 2022
1fa13c7
update width docstring
willschlitzer Jan 4, 2022
a3b9af2
Apply suggestions from code review
willschlitzer Jan 5, 2022
9266be1
re-add region docstring alias
willschlitzer Jan 5, 2022
f776087
Merge branch 'main' into wrap-ternary
willschlitzer Jan 19, 2022
2385135
update test_ternary.py to use a fixture array
willschlitzer Jan 19, 2022
a383101
update dvc hash for test_ternary.png.dvc
willschlitzer Jan 19, 2022
2999f5b
Merge branch 'main' into wrap-ternary
willschlitzer Apr 13, 2022
b5087ec
Apply suggestions from code review
willschlitzer Apr 19, 2022
845fbbd
Merge branch 'main' into wrap-ternary
willschlitzer Apr 19, 2022
509384b
Apply suggestions from code review
willschlitzer Sep 12, 2022
395efb0
Merge branch 'main' into wrap-ternary
willschlitzer Sep 12, 2022
f7f37da
[format-command] fixes
actions-bot Sep 12, 2022
9b364a8
Update pygmt/src/ternary.py
willschlitzer Sep 13, 2022
cfd7ae7
update test_ternary.png.dvc
willschlitzer Sep 13, 2022
33b200e
run make format
willschlitzer Sep 13, 2022
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
1 change: 1 addition & 0 deletions doc/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Plotting tabular data
Figure.plot
Figure.plot3d
Figure.rose
Figure.ternary
Figure.velo
Figure.wiggle

Expand Down
1 change: 1 addition & 0 deletions pygmt/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ def _repr_html_(self):
set_panel,
solar,
subplot,
ternary,
text,
velo,
wiggle,
Expand Down
1 change: 1 addition & 0 deletions pygmt/src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
from pygmt.src.sphinterpolate import sphinterpolate
from pygmt.src.subplot import set_panel, subplot
from pygmt.src.surface import surface
from pygmt.src.ternary import ternary
from pygmt.src.text import text_ as text # "text" is an argument within "text_"
from pygmt.src.velo import velo
from pygmt.src.which import which
Expand Down
59 changes: 59 additions & 0 deletions pygmt/src/ternary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"""
ternary - Plot data on ternary diagrams.
"""
from pygmt.clib import Session
from pygmt.helpers import build_arg_string, fmt_docstring, kwargs_to_strings, use_alias


@fmt_docstring
@use_alias(
B="frame",
C="cmap",
F="center",
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved
G="fill",
JX="projection",
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved
R="region",
S="style",
U="timestamp",
V="verbose",
W="pen",
X="xshift",
Y="yshift",
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved
p="perspective",
t="transparency",
)
@kwargs_to_strings(R="sequence", T="sequence", c="sequence_comma", p="sequence")
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved
def ternary(self, table, **kwargs):
seisman marked this conversation as resolved.
Show resolved Hide resolved
r"""
Plots a histogram, and can read data from a file or
list, array, or dataframe.
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved

Full option list at :gmt-docs:`histogram.html`
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved

{aliases}

Parameters
----------
table : str or list or {table-like}
Pass in either a file name to an ASCII data table, a Python list, a 2D
{table-classes}.
{J}
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved
{R}
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved
{CPT}
{G}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

G is aliased to fill, but the docstring here says color. Xref #1617

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried using G=["fill", "color"] but it didn't pass the tesing/documentation build. Am I missing a step?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried using G=["fill", "color"] but it didn't pass the tesing/documentation build. Am I missing a step?

Need the rewrite the use_alias decorator to support the multi-alias mechanism like G=["fill", "color"].

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that falls outside of the scope of this pull request. I'll convert this to draft for the time being.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can ignore it now and address the issue in #1617 instead.

style : str
Plot symbols (including vectors, pie slices, fronts, decorated or
quoted lines).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to expand the docstring of style, so that users understand what style="c0.2c" means.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a standard as to what should be used? pygmt.plot has the same docstring for style.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think rather than adding a lot of text, we could add a link to the symbols and markers gallery page similar to what is done for the region, frame, and projection docstring sections.

willschlitzer marked this conversation as resolved.
Show resolved Hide resolved
{W}
{XY}
{U}
{V}
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved
{p}
{t}
"""
kwargs = self._preprocess(**kwargs) # pylint: disable=protected-access
with Session() as lib:
file_context = lib.virtualfile_from_data(check_kind="vector", data=table)
with file_context as infile:
arg_str = " ".join([infile, build_arg_string(kwargs)])
lib.call_module("ternary", arg_str)
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 4 additions & 0 deletions pygmt/tests/baseline/test_ternary.png.dvc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: 9f6b57e9dd82aa24a8a013176ba8fb1d
size: 128744
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved
path: test_ternary.png
22 changes: 22 additions & 0 deletions pygmt/tests/test_ternary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""
Tests ternary.
"""
import pytest
from pygmt import Figure


@pytest.mark.mpl_image_compare
def test_ternary():
"""
Test plotting a ternary chart.
"""
fig = Figure()
fig.ternary(
table="@ternary.txt",
region="0/100/0/100/0/100",
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved
cmap="red,orange,yellow,green,blue,violet",
projection="6i",
frame=["bafg+lAir", "cafg+lLimestone", "aafg+lWater"],
style="c0.1c",
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved
)
return fig