Skip to content

Add gallery example for Figure.ternary method #2138

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

Merged
merged 16 commits into from
Dec 27, 2022
Merged
Changes from 15 commits
Commits
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
44 changes: 44 additions & 0 deletions examples/gallery/basemaps/ternary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""
Ternary diagram
---------------
The :meth:`pygmt.Figure.ternary` method can draw ternary diagrams. The example
shows how to plot circles with a diameter of 0.1 centimeters
(``style="c0.1c"``) on a 10-centimeter-wide (``width="10c"``) ternary diagram
at the positions listed in the first three columns of the sample dataset
``rock_compositions``, with default annotations and gridline spacings, using
the specified labeling defined via ``alabel``, ``blabel`` and ``clabel``.
Points are colored based on the values given in the fourth columns of the
sample dataset via ``cmap=True``.
"""

import pygmt

fig = pygmt.Figure()

# Load sample data
data = pygmt.datasets.load_sample_data(name="rock_compositions")

# Define a colormap to be used for the values given in the fourth column
# of the input dataset
pygmt.makecpt(cmap="batlow", series=[0, 80, 10])

fig.ternary(
data,
region=[0, 100, 0, 100, 0, 100],
width="10c",
style="c0.1c",
alabel="Limestone",
blabel="Water",
clabel="Air",
cmap=True,
frame=[
"aafg+lLimestone component+u %",
"bafg+lWater component+u %",
"cagf+lAir component+u %",
],
)

# Add a colorbar indicating the values given in the fourth column of
# the input dataset
fig.colorbar(position="JBC+o0c/1.5c", frame=["x+lPermittivity"])
fig.show()