UP | HOME

Barycentric Plots in gnuplot

Table of Contents

Authors
Giulio Bottazzi
Date
26 September 2006
Revision
0.2
Copyright
GPL

Some mathematical details

Consider an equilateral triangle and number its sides (and the opposing vertices) with 1, 2 and 3. Now take a point \(P\) inside the triangle and let \(h_1\), \(h_2\) and \(h_3\) be the distance of this point from side 1, 2 and 3 respectively. It is easy to show that for any point \(P\) it is \[ h_1+h_2+h_3 = { \sqrt{3} \over 2} l \] where \(l\) is the length of the triangle side.

Now consider a triangle with sides of unit length and imagine to embed it in a Cartesian system, with vertex 3 in the origin and side 1 along the $x$-axis. Vertex 1 is then at position \((1/2,\sqrt{3}/2)\) and vertex 2 at \((0,1/2)\). It is easy to see that an internal point P at distances h1 and h2 from side 1 and 2 respectively has coordinates \[ \left( {h_1 \over \sqrt{3} } + 2 {h_2 \over \sqrt{3}} , h_1 \right) \]

Barycentric coordinates

The above properties can be exploited to represent a function defined over the 2 dimensional simplex, that is over the triplet of points \((x_1,x_2,x_3)\) which satisfy the condition \[ x_1+x_2+x_3=1 \quad x_1,x_2,x_3>0 . \]

Indeed, with the identification \(h_i=\sqrt{3}/2 x_i\) for \(i=1,2,3\), this relation is identical to the one given above concerning the sum of the distances of an interior point of an equilateral triangle from its sides. In the Cartesian system, the point \((x_1,x_2,x_3)\) is then represented by the couple of coordinates \[ \left( {1 \over 2} x_1+x_2 , {\sqrt{3} \over 2 } x_1 \right) \] The two dimensional unit simplex is mapped in the equilateral triangle of side \(2/\sqrt{3}\). In this representation, if the point \(P\) is nearer to the vertex 1, it means that \(x_1> x_2,x_3\). If the point is on one side, than the coordinate associated with the opposing vertex is zero. If it is on one vertex, than the associated coordinate is 1 (and the remaining two coordinates are zero).

Gnuplot representation

Imagine to have the function \(f(x_1,x_2)\) defined over the unit 2-simplex. When data are generated, the coordinates \((x_1,x_2)\) should be transformed according to the equation above. This the points are automatically placed inside the equilateral triangle with its side 1 over the $x$-axis. The picture can be beautified applying some changes to the default setting. First of all remove the Cartesian axes and the associated ticks

unset border
unset xtics
unset ytics

and substitute it with the proper triangular frame

set arrow 1 from 0,0 to .5,sqrt(3)/2 nohead front lt -1 lw 1
set arrow 2 from 0,0 to 1,0          nohead front lt -1 lw 1
set arrow 3 from 1,0 to .5,sqrt(3)/2 nohead front lt -1 lw 1

properly numbering the vertex

set label 1 "1" at 0.5,sqrt(3)/2+.05
set label 2 "2" at 1+.05,0
set label 3 "3" at -.05,0

At this point you can draw a surface plot or also a map using the usual gnuplot options.

Created: 2023-08-04 Fri 19:24