Skip to content
Merged
Changes from 11 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
48 changes: 48 additions & 0 deletions examples/gallery/embellishments/ternary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""
Ternary diagram
---------------
The pygmt.Figure.ternary method can draw ternary diagrams. The example shows
how to plot circles with a diameter of 0.1 centimeters (``style=0.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 %",
],
)

# Shift origin -1 centimeters in y direction to avoid overlap
# between ternary diagram and colorbar
fig.shift_origin(yshift="-1c")

# Add a colorbar indicating the values given in the fourth column of
Copy link
Member

Choose a reason for hiding this comment

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

Here is the plot generated using the default Figure.colorbar(frame=["x+lPermittivity"]) call. I feel the default location of the colorbar should be improved on the GMT side. What do you think?

map

Copy link
Member

Choose a reason for hiding this comment

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

I am thinking the way that ternary frame is drawn the colorer module has no way of knowing that axes was annotated so it does not add any space (or it is not in the right hidden file in the session dir). If a CLI equivalent script can be made I might be able to have a look.

Copy link
Member

Choose a reason for hiding this comment

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

Here is the CLI version:

gmt begin map
gmt makecpt -Cturbo -T0/80/10
gmt ternary @ternary.txt -R0/100/0/100/0/100 -JX6i -Sc0.1c -C -LWater/Air/Limestone \
    -Baafg+l"Water component"+u" %" -Bbafg+l"Air component"+u" %" -Bcagf+l"Limestone component"+u" %" \
    -B+givory+t"Example data from MATLAB Central"
gmt colorbar
gmt end show

map

Copy link
Member Author

Choose a reason for hiding this comment

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

Here is the plot generated using the default Figure.colorbar(frame=["x+lPermittivity"]) call. I feel the default location of the colorbar should be improved on the GMT side. What do you think?

Totally agree with you @seisman, would be great if the colorbar is placed without any direction shiftings.

# the input dataset
fig.colorbar(frame=["x+lPermittivity"])
fig.show()