Manual for Package pgfplots
2D/3D Plots in LATeX, Version 1.18.1
http://sourceforge.net/projects/pgfplots
Related Libraries
5.13Ternary Diagrams
-
\usepgfplotslibrary{ternary} % LaTeX and plain TeX ¶
-
\usepgfplotslibrary[ternary] % ConTeXt ¶
-
\usetikzlibrary{pgfplots.ternary} % LaTeX and plain TeX ¶
-
\usetikzlibrary[pgfplots.ternary] % ConTeXt ¶
A library to draw ternary diagrams.
A ternary diagram visualizes three-component systems such that the sum of them yields \(100\%\). Ternary diagrams are triangular axes.
5.13.1Ternary Axis¶
-
\begin{ternaryaxis}[options] ¶
-
environment contents ¶
-
\end{ternaryaxis} ¶
The axis environment for ternary axes.
A ternaryaxis works with relative coordinates: each data point consists of three components \(x\), \(y\), \(z\). Their sum forms a compound entity which has \(100\%\) (of whatever). In the standard configuration, we have \(x,y,z \in [0,1]\). The unit interval is not necessary: you can as well choose absolute data ranges \(x \in [x_{\min },x_{\max }]\), \(y \in [y_{\min },y_{\max }]\) and \(z \in [z_{\min },z_{\max }]\). The important thing is that the relative values
\[ \tilde x := \frac {x-x_{\min }}{x_{\max } - x_{\min }},\; \tilde y := \frac {y-y_{\min }}{y_{\max } - y_{\min }},\; \tilde z := \frac {z-z_{\min }}{z_{\max } - z_{\min }} \]
sum up to \(100\%\), i.e. \(\tilde x + \tilde y + \tilde z = 1\). Thus, pgfplots computes \(\tilde x\), \(\tilde y\) and \(\tilde z\) and interprets them as barycentric (triangular) coordinates.
For this to work, it is crucial to provide xmin, xmax, ymin, ymax and zmin, zmax precisely! The initial configuration fixes them to the unit interval.
What happens behind the scenes is that a data point \((x,y,z)\) is placed at \(X,Y\) determined by
\[ \begin {bmatrix} X(x,y,z)\\ Y(x,y,z) \end {bmatrix} = \tilde x A + \tilde y B + \tilde z C = \begin {bmatrix} \frac 12 {\tilde x+2 \tilde z}\\ \frac {\sqrt 3}{2} {\tilde x} \end {bmatrix} \]
where \(A=(\nicefrac 12,\nicefrac {\sqrt 3}{2})\) is top corner of the triangle, \(B=(0,0)\) the lower left and \(C=(1,0)\) the lower right one. The \(\tilde y\) component is not really necessary due to the linear dependency \(\tilde x+\tilde y+\tilde z=1\).
The input coordinate \((100\%,0\%,0\%)\) is mapped to \(A\), the input coordinate \((0\%,100\%,0\%)\) to \(B\) and \((0\%,0\%,100\%)\) to \(C\) (Acrobat Reader: click into the axis to verify it).
A ternaryaxis can contain zero, one or more \addplot3 commands, just as a usual axis. In case you provide only two-dimensional coordinates (for example using \addplot or axis cs), the third component is deduced automatically such that components sum to \(100\%\). The \addplot3 command can use any of the accepted input formats, for example using coordinates, table, expression or whatever – but the input is always interpreted as barycentric coordinates (three components summing up to \(100\%\)).
A ternaryaxis supports (most of) the pgfplots axis interface, among them the grid option, the xtick={positions} way to provide ticks, including extra x ticks and its variants. Of course, it can also contain any of the mark, color and cycle list options of a normal axis.
The following example is a (crude) copy of an example of
http://www.sv.vt.edu/classes/MSE2094_NoteBook/96ClassProj/experimental/ternary2.html
and uses area style to change cycle list and the legend appearance.
Ternary plots can also use contour prepared to plot contour lines. The following example is a (crude) copy of an example of
http://www.sv.vt.edu/classes/MSE2094_NoteBook/96ClassProj/experimental/ternary2.html:
The contour prepared={labels over line} installs the display style contour/labels over line and expects precomputed contour lines from the input stream. Here, the input stream is a table, consisting of the three relative components for Chromium, Iron and Nickel – and the point meta is set to be the Temperature column. The contour prepared style uses the \((x,y,z)\) coordinate to plot the data point and the point meta to determine contour labels (the initial configuration of contour prepared is to use point meta=z). The output thus allows to use both barycentric coordinates (ternary components) and contour labels.
-
/pgfplots/ternary limits relative=true|false (initially true) ¶
-
/pgfplots/ternary relative limits=true|false (initially true) ¶
Allows to switch tick labels between relative numbers in the range \([0,100]\) or absolute numbers.
The choice ternary limits relative=true accepts data in any input number range, for example \((x,y,z) \in [0,1]^3\), or \((x,y,z) \in [0,100]^3\) or in any absolute scala of the form \(x_i \in [\underline x_i,\overline x_i]\) for \(x_i \in \{x,y,z\}\) (remember that it is crucial to communicate these limits to pgfplots explicitly using xmin, xmax, ymin, ymax and zmin, zmax such that relative coordinates can be computed, see the description above for details). In every case, relative tick labels are drawn, i.e. tick labels in the range \([0,100]\).
The choice ternary limits relative=false accepts the same data ranges, but it draws tick labels in the very same data ranges.
-
Coordinate system cartesian cs ¶
A coordinate system which allows Cartesian coordinates. The lower left point has coordinate \((0,0)\), the lower right point has \((1,0)\) and the upper point of the triangle is at \((\nicefrac {1}{2}, \nicefrac {\sqrt 3}{2})\).
Note that you need to prefix the coordinate with cartesian cs:; otherwise pgfplots will interpret the coordinate as ternary (since compat=1.11).
-
/pgfplots/every ternary axis(style, no value) ¶
A style which is installed at the beginning of every ternary axis. It is used to adjust some of the pgfplots keys to fit the triangular shape.
The initial configuration is
5.13.2Tieline Plots¶
-
/tikz/tieline={options with tieline/ prefix} ¶
-
\addplot+[tieline={options with tieline/ prefix}]
-
/pgfplots/table/tie end x={colname} (initially empty) ¶
-
/pgfplots/table/tie end y={colname} (initially empty) ¶
-
/pgfplots/table/tie end z={colname} (initially empty) ¶
-
/pgfplots/table/tie end x index={col index} (initially empty) ¶
-
/pgfplots/table/tie end y index={col index} (initially empty) ¶
-
/pgfplots/table/tie end z index={col index} (initially empty) ¶
-
/pgfplots/tieline/each nth tie={number} (initially empty) ¶
-
/pgfplots/tieline/tieline style={options} ¶
-
/pgfplots/tieline/curve style={options} ¶
A plot handler for use in ternary diagrams which plots tie lines and binodal curves.
On input, it accepts pairs of coordinates, \(A^{(i)}=(A_x^{(i)},A_y^{(i)},A_z^{(i)})\) and \(B^{(i)}=(B_x^{(1)},B_y^{(2)},B_z^{(3)})\), for \(i=1,\dotsc ,N\) (i.e. it requires a total of six coordinates, perhaps plus additional color data).
On output, it connects the pairs, i.e. for every fixed \(i=1,\dotsc ,N\), it connects \(A^{(i)}\) – \(B^{(i)}\) (the so-called “tie lines”). In addition, it also draws the binodal curve, which is made up by connecting all \(A^{(i)}\) and then, in reverse ordering, all \(B^{(i)}\): \(A^{(1)}\) – \(A^{(2)}\) – \(\dotsb \) – \(A^{(N)}\) – \(B^{(N)}\) – \(B^{(N-1)}\) – \(\dotsb \) – \(B^{(1)}\):
We see that each input line has six columns, and each six columns are taken into account (this is different from other plot handlers!). The six columns make up the three components of the \(A\) and \(B\) points, respectively. In the example above, we used explicit column names and provided \(A_x\) using x=A_IPA, \(A_y\) using y=A_water and \(A_z\) using z=A_propene. Note that these keys are the common input method for \addplot table; they are nothing special (that means we could also use x index instead). The three columns for \(B\) can be provided manually (see below), or deduced automatically: in our case, the value for \(B_x\) has been found in the third column after x=A_IPA (which is B_IPA); the value for \(B_y\) has been found in the third column after y=A_water and \(B_z\) is made up from the third column after z=A_propene. In other words, the \(B\) value is searched (by default) by adding \(3\) to the column index of the respective \(A\) coordinate.
You do not need to provide any column names; in this case, the first three columns make up \(A\) (in the order of appearance) and the following three make up \(B\).
The only supported input type for tieline plots is table input. It is optimized to use \addplot3 table (as described above). To use the two-dimensional variant \addplot table, you need to tell pgfplots explicitly which columns make up \(A_x,A_y,B_x,B_y\); the \(z\)-coordinates are deduced automatically such that the result sums to \(100\%\).
These keys can be used to provide column names or column indices for \(B_x\), \(B_y\) and \(B_z\), respectively. They can be provided like
\addplot3[tieline] table[tie end y=B_water] ....
Note that the tie end x keys are only available if the tieline option has been used before.
The values for \(A\) are provided with table/x, table/x index and its variants as for any other plot type.
The tieline plot handler accepts several options to customize the appearance. You can provide them as argument after tieline, using tieline={options}. In this case, the tieline/ prefix can be omitted. The keys are described in the following:
Allows to draw only each \(n\)th tie line, even though the binodal curve uses all provided coordinates:
Note that plot marks (if any) are drawn on every input position, use the mark repeat option to change that.
Appends options to the style tieline/every tieline.
Useful options are, for example, other plot handlers to adjust the appearance of tie lines. Suppose that you have additional color data for every tie line (which might have been provided as further input column). In our case, we provide random color data using point meta=rand, and visualize the single tielines as with contour prepared:
The effect here is that contour labels and line colors are chosen for every tie line, where the actual color is determined using point meta and colormap. Other choices for plot handlers in tieline style might be the mesh.
Appends options to the style tieline/every curve.
The curve style allows to customize the plot handler for the curve. A possible choice might be curve style={smooth} or a separate fill/draw color.