Drawing ternary diagrams

Ternary (triangular) diagrams are common in earth sciences. Here, I introduce some opensource (free) softwares to draw ternary diagrams.

Application for Mac OSX

ΔPlot

ΔPlot (Delta Plot) is a free software to plot data in ternary diagrams. Detailed explanation is shown here. It includes a lot of useful templates for earth sciences such as mineralogy, petrology, and sedimentary petrology. Mac OSX 10.2 or later is required. It is the easiest way, if you use Mac.

Opensource softwares

Gnuplot

Gnuplot is a free software to visualize 2D and 3D data. It works in Windows, Mac, and Unix (Linux). It cannot deal with ternary diagrams directly, so that some calculations are needed prior to plotting data. Here, we use AWK (or Gawk) in the gnuplot script.

At first, three elements (x, y, z) are reduced into two to plot in the X-Y coordinate. The method is the same as the ΔPlot.

XY

The ternary diagram has three apices (x, y, z) counterclockwise. The length of one side sets to 1.

ternary

For example, the following data with three values (x, y, z) and label (A–F) are saved as data.dat.

32.4  21.3  46.3  A
21.1  13.4  65.5  B
72.4  5.2   22.4  C
33.3  30.3  36.4  D
0.3   1.2   98.5  E
70.5  29.1  0.4   F

If the next script is saved as data.gpl and run the command `gnuplot data.gpl', ternary_gpl.eps will be generated.

set terminal postscript enhanced 18
set bmargin 3
set lmargin 3
set rmargin 3
set tmargin 3
set size ratio 0.866
set yrange [0:0.866]
set xrange [0:1]
set noborder
set noxtics
set noytics
set label 'Y' at 0, -0.03 center
set label 'Z' at 1, -0.03 center
set label 'X' at 0.5, 0.886 center
set output 'ternary_gpl.eps'

set style line 1 lt 1 lw 3 pt -1 ps 1
set style line 2 lt 5 lw 1 pt -1 ps 1

# x
set arrow 1 from 0,0 to 1, 0.0 nohead linestyle 1
set arrow 2 from 0.1,0 to 0.55, 0.779 nohead linestyle 2
set arrow 3 from 0.2,0 to 0.60, 0.693 nohead linestyle 2
set arrow 4 from 0.3,0 to 0.65, 0.606 nohead linestyle 2
set arrow 5 from 0.4,0 to 0.70, 0.520 nohead linestyle 2
set arrow 6 from 0.5,0 to 0.75, 0.433 nohead linestyle 2
set arrow 7 from 0.6,0 to 0.80, 0.346 nohead linestyle 2
set arrow 8 from 0.7,0 to 0.85, 0.260 nohead linestyle 2
set arrow 9 from 0.8,0 to 0.90, 0.173 nohead linestyle 2
set arrow 10 from 0.9,0 to 0.95, 0.0866 nohead linestyle 2

# z
set arrow 11 from 1, 0 to 0.50, 0.866 nohead linestyle 1
set arrow 12 from 0.95, 0.0866 to 0.05, 0.0866 nohead linestyle 2
set arrow 13 from 0.90, 0.173 to 0.10, 0.173 nohead linestyle 2
set arrow 14 from 0.85, 0.260 to 0.15, 0.260 nohead linestyle 2
set arrow 15 from 0.80, 0.346 to 0.20, 0.346 nohead linestyle 2
set arrow 16 from 0.75, 0.433 to 0.25, 0.433 nohead linestyle 2
set arrow 17 from 0.70, 0.520 to 0.30, 0.520 nohead linestyle 2
set arrow 18 from 0.65, 0.606 to 0.35, 0.606 nohead linestyle 2
set arrow 19 from 0.60, 0.693 to 0.40, 0.693 nohead linestyle 2
set arrow 20 from 0.55, 0.779 to 0.45, 0.779 nohead linestyle 2

# y
set arrow 21 from 0.50, 0.866 to 0,0 nohead linestyle 1
set arrow 22 from 0.05, 0.0866 to 0.1,0 nohead linestyle 2
set arrow 23 from 0.10, 0.173 to 0.2,0 nohead linestyle 2
set arrow 24 from 0.15, 0.260 to 0.3,0 nohead linestyle 2
set arrow 25 from 0.20, 0.346 to 0.4,0 nohead linestyle 2
set arrow 26 from 0.25, 0.433 to 0.5,0 nohead linestyle 2
set arrow 27 from 0.30, 0.520 to 0.6,0 nohead linestyle 2
set arrow 28 from 0.35, 0.606 to 0.7,0 nohead linestyle 2
set arrow 29 from 0.40, 0.693 to 0.8,0 nohead linestyle 2
set arrow 30 from 0.45, 0.779 to 0.9,0 nohead linestyle 2

plot "<awk '{print ($1+2*$3)/(2*($1+$2+$3)), sqrt(3)*$1/(2*($1+$2+$3))}' data.dat" t 'data' w p pt 7
ternary_gpl

Gnuplot can generate pdf, png, jpg, gif, and many other formats, in addition to eps.

Back to TOP

GMT

GMT is originally an opensource software to illustrate topographic maps, and can draw X–Y graphs, too. Here we plot a ternary diagram using the previous data.dat. After the following script is saved as ternary.gmt and run, ternary_gmt.eps will be produced.

#!/bin/sh
# Ternary diagrams
gmtset PAPER_MEDIA a4+
gmtset LABEL_FONT_SIZE 10

t_title="X"
l_title="Z"
r_title="Y"
outfile=ternary_gmt.eps

side=15
psxy -R0/1/0/1 -JX$side -P -K /dev/null > $outfile

# Bottom axis:
psbasemap -R -JX -O -K -Bf0.1S >> $outfile

pstext -JX -R -O -K -V -N <<EOD>>$outfile
-0.05  -0.05  24  0  0	1  $l_title
0.48   0.88   24  0  0	1  $t_title
1      -0.05  24  0  0	1  $r_title
EOD

# Left tilted axis
echo "gsave -30 rotate" >> $outfile
psbasemap -R -JX -O -K -Bf0.1W >> $outfile
echo "grestore" >> $outfile
x=`gmtmath -Q $side $side 30 COSD MUL SUB =`
y=`gmtmath -Q $side 30 SIND MUL NEG =`
psxy -R -JX -O -K -X$x -Y$y /dev/null >> $outfile

# Right tilted axis
echo "gsave 30 rotate" >> $outfile
psbasemap -R -JX -O -K -Bf0.1E >> $outfile
echo "grestore" >> $outfile
x=`gmtmath -Q $x NEG =`
y=`gmtmath -Q $y NEG =`
psxy -R -JX -O -K -X$x -Y$y /dev/null >> $outfile

awk '{print ($1+2*$3)/(2*($1+$2+$3)), sqrt(3)*$1/(2*($1+$2+$3))}' data.dat | \
    psxy -JX -R -O -V -Sc0.18 -G0 -N >> $outfile
ternary_gmt.png

If the next script is inserted in the middle of the script, the data labels will be added in the diagram.

awk '{print ($1+2*$3)/(2*($1+$2+$3))+0.005, sqrt(3)*$1/(2*($1+$2+$3))+0.005, 12, 0, 0, 1, $4}' data.dat | \
    pstext -JX -R -O -V -K -N >> $outfile
ternary_gmt2.png

Back to TOP


Back