Skip to content

Commit a1e50ac

Browse files
michaelgrundseismanwillschlitzeryvonnefroehlich
authored
Add gallery example for Figure.ternary method (#2138)
Co-authored-by: Dongdong Tian <[email protected]> Co-authored-by: Will Schlitzer <[email protected]> Co-authored-by: Yvonne Fröhlich <[email protected]>
1 parent 7c67cf0 commit a1e50ac

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"""
2+
Ternary diagram
3+
---------------
4+
The :meth:`pygmt.Figure.ternary` method can draw ternary diagrams. The example
5+
shows how to plot circles with a diameter of 0.1 centimeters
6+
(``style="c0.1c"``) on a 10-centimeter-wide (``width="10c"``) ternary diagram
7+
at the positions listed in the first three columns of the sample dataset
8+
``rock_compositions``, with default annotations and gridline spacings, using
9+
the specified labeling defined via ``alabel``, ``blabel``, and ``clabel``.
10+
Points are colored based on the values given in the fourth columns of the
11+
sample dataset via ``cmap=True``.
12+
"""
13+
14+
import pygmt
15+
16+
fig = pygmt.Figure()
17+
18+
# Load sample data
19+
data = pygmt.datasets.load_sample_data(name="rock_compositions")
20+
21+
# Define a colormap to be used for the values given in the fourth column
22+
# of the input dataset
23+
pygmt.makecpt(cmap="batlow", series=[0, 80, 10])
24+
25+
fig.ternary(
26+
data,
27+
region=[0, 100, 0, 100, 0, 100],
28+
width="10c",
29+
style="c0.1c",
30+
alabel="Limestone",
31+
blabel="Water",
32+
clabel="Air",
33+
cmap=True,
34+
frame=[
35+
"aafg+lLimestone component+u %",
36+
"bafg+lWater component+u %",
37+
"cagf+lAir component+u %",
38+
],
39+
)
40+
41+
# Add a colorbar indicating the values given in the fourth column of
42+
# the input dataset
43+
fig.colorbar(position="JBC+o0c/1.5c", frame=["x+lPermittivity"])
44+
fig.show()

0 commit comments

Comments
 (0)