tikz.dev / PGFplots Manual

Manual for Package pgfplots
2D/3D Plots in LA, Version 1.18.1
http://sourceforge.net/projects/pgfplots

Utilities and Basic Level Commands

\(\newcommand{\footnotename}{footnote}\) \(\def \LWRfootnote {1}\) \(\newcommand {\footnote }[2][\LWRfootnote ]{{}^{\mathrm {#1}}}\) \(\newcommand {\footnotemark }[1][\LWRfootnote ]{{}^{\mathrm {#1}}}\) \(\let \LWRorighspace \hspace \) \(\renewcommand {\hspace }{\ifstar \LWRorighspace \LWRorighspace }\) \(\newcommand {\mathnormal }[1]{{#1}}\) \(\newcommand \ensuremath [1]{#1}\) \(\newcommand {\LWRframebox }[2][]{\fbox {#2}} \newcommand {\framebox }[1][]{\LWRframebox } \) \(\newcommand {\setlength }[2]{}\) \(\newcommand {\addtolength }[2]{}\) \(\newcommand {\setcounter }[2]{}\) \(\newcommand {\addtocounter }[2]{}\) \(\newcommand {\arabic }[1]{}\) \(\newcommand {\number }[1]{}\) \(\newcommand {\noalign }[1]{\text {#1}\notag \\}\) \(\newcommand {\cline }[1]{}\) \(\newcommand {\directlua }[1]{\text {(directlua)}}\) \(\newcommand {\luatexdirectlua }[1]{\text {(directlua)}}\) \(\newcommand {\protect }{}\) \(\def \LWRabsorbnumber #1 {}\) \(\def \LWRabsorbquotenumber "#1 {}\) \(\newcommand {\LWRabsorboption }[1][]{}\) \(\newcommand {\LWRabsorbtwooptions }[1][]{\LWRabsorboption }\) \(\def \mathchar {\ifnextchar "\LWRabsorbquotenumber \LWRabsorbnumber }\) \(\def \mathcode #1={\mathchar }\) \(\let \delcode \mathcode \) \(\let \delimiter \mathchar \) \(\def \oe {\unicode {x0153}}\) \(\def \OE {\unicode {x0152}}\) \(\def \ae {\unicode {x00E6}}\) \(\def \AE {\unicode {x00C6}}\) \(\def \aa {\unicode {x00E5}}\) \(\def \AA {\unicode {x00C5}}\) \(\def \o {\unicode {x00F8}}\) \(\def \O {\unicode {x00D8}}\) \(\def \l {\unicode {x0142}}\) \(\def \L {\unicode {x0141}}\) \(\def \ss {\unicode {x00DF}}\) \(\def \SS {\unicode {x1E9E}}\) \(\def \dag {\unicode {x2020}}\) \(\def \ddag {\unicode {x2021}}\) \(\def \P {\unicode {x00B6}}\) \(\def \copyright {\unicode {x00A9}}\) \(\def \pounds {\unicode {x00A3}}\) \(\let \LWRref \ref \) \(\renewcommand {\ref }{\ifstar \LWRref \LWRref }\) \( \newcommand {\multicolumn }[3]{#3}\) \(\require {textcomp}\) \( \newcommand {\meta }[1]{\langle \textit {#1}\rangle } \) \(\newcommand {\toprule }[1][]{\hline }\) \(\let \midrule \toprule \) \(\let \bottomrule \toprule \) \(\def \LWRbooktabscmidruleparen (#1)#2{}\) \(\newcommand {\LWRbooktabscmidrulenoparen }[1]{}\) \(\newcommand {\cmidrule }[1][]{\ifnextchar (\LWRbooktabscmidruleparen \LWRbooktabscmidrulenoparen }\) \(\newcommand {\morecmidrules }{}\) \(\newcommand {\specialrule }[3]{\hline }\) \(\newcommand {\addlinespace }[1][]{}\) \(\require {colortbl}\) \(\let \LWRorigcolumncolor \columncolor \) \(\renewcommand {\columncolor }[2][named]{\LWRorigcolumncolor [#1]{#2}\LWRabsorbtwooptions }\) \(\let \LWRorigrowcolor \rowcolor \) \(\renewcommand {\rowcolor }[2][named]{\LWRorigrowcolor [#1]{#2}\LWRabsorbtwooptions }\) \(\let \LWRorigcellcolor \cellcolor \) \(\renewcommand {\cellcolor }[2][named]{\LWRorigcellcolor [#1]{#2}\LWRabsorbtwooptions }\) \(\newcommand {\intertext }[1]{\text {#1}\notag \\}\) \(\let \Hat \hat \) \(\let \Check \check \) \(\let \Tilde \tilde \) \(\let \Acute \acute \) \(\let \Grave \grave \) \(\let \Dot \dot \) \(\let \Ddot \ddot \) \(\let \Breve \breve \) \(\let \Bar \bar \) \(\let \Vec \vec \) \(\newcommand {\nicefrac }[3][]{\mathinner {{}^{#2}\!/\!_{#3}}}\)

9.4Specifying Basic Coordinates

  • \pgfplotspointaxisxy{(math image)x coordinate(math image)}{(math image)y coordinate(math image)}

  • \pgfplotspointaxisxyz{(math image)x coordinate(math image)}{(math image)y coordinate(math image)}{(math image)z coordinate(math image)}

  • Point commands like \pgfpointxy which take logical, absolute coordinates and return a low-level point. Every transformation from user transformations to logarithms is applied.

    Since the transformations are initialized after the axis is complete, this command needs to be postponed (see \pgfplotsextra).

    This command is the basic level variant of axis cs:(math image)x coordinate(math image),(math image)y coordinate(math image),(math image)z coordinate(math image).

    Note that this is also the default coordinate system during the visualization phase; in other words: if you write \draw (1,2) -- (1,4), pgfplots will automatically use (axis cs:1,2) -- (axis cs:1,4).

  • \pgfplotspointrelaxisxy{(math image)rel x coordinate(math image)}{(math image)rel y coordinate(math image)}

  • \pgfplotspointrelaxisxyz{(math image)rel x coordinate(math image)}{(math image)rel y coordinate(math image)}{(math image)rel z coordinate(math image)}

  • Point commands which take relative coordinates such that \(x=0\) is the lower \(x\)-axis limit and \(x=1\) the upper \(x\)-axis limit.

    These commands are used for rel axis cs.

    Please note that the transformations are only initialised if the axis is complete! This means you need to provide \pgfplotsextra.

  • \pgfplotspointdescriptionxy{(math image)\(x\) fraction(math image)}{(math image)\(y\) fraction(math image)}

  • \pgfplotsqpointdescriptionxy{(math image)\(x\) fraction(math image)}{(math image)\(y\) fraction(math image)}

  • Point commands such that {0}{0} is the lower left corner of the axis’ bounding box and {1}{1} the upper right one; everything else is in between. The ‘q’ variant is quicker as it doesn’t invoke the math parser on its arguments.

    They are used for axis description cs, see Section 4.9.1.

  • \pgfplotspointaxisorigin

  • A point coordinate at the origin, \((0,0,0)\). If the origin is not part of the axis limits, the nearest point on the boundary is returned instead.

    This is the same coordinate as returned by the origin anchor.

  • \pgfplotstransformcoordinatex{(math image)x coordinate of an axis(math image)}

  • \pgfplotstransformcoordinatey{(math image)y coordinate of an axis(math image)}

  • \pgfplotstransformcoordinatez{(math image)z coordinate of an axis(math image)}

  • Defines \pgfmathresult to be the low-level pgf coordinate corresponding to the input argument.

    The command applies any [xyz] coord trafo keys, data scalings and/or logarithms or whatever pgfplots does to map input coordinates to internal coordinates.

    The result can be used inside of a \pgfpointxy statement (i.e. it still needs to be scaled with the respective pgf unit vector).

    (-tikz- diagram)

    % Preamble: \pgfplotsset{width=7cm,compat=1.18} \begin{tikzpicture} \pgfplotsset{compat/pgfpoint substitution=1.3} \begin{axis}[xmin=0,xmax=2,ymin=0,ymax=5] \pgfplotsextra{ \pgfplotstransformcoordinatex{1} \let\xcoord=\pgfmathresult \pgfplotstransformcoordinatey{1} \let\ycoord=\pgfmathresult \pgfpathcircle {\pgfqpointxy{\xcoord}{\ycoord}} {5pt} \pgfusepath{fill} } \end{axis} \end{tikzpicture}

    Note that pgfplots substitutes \pgfqpointxy by \pgfplotspointaxisxyz by default – and this command implicitly transforms coordinates anyway. In order to see the difference, the preceding example first disables this automatic substition of coordinate systems by means of compat/pgfpoint substitution=1.3. The result of this command is also available as math method transformcoordinatex (see the documentation for axis cs).

    Please note that the transformations are only initialised if the axis is complete. This means you need to provide \pgfplotsextra as is shown in the example above.

  • \pgfplotstransformdirectionx{(math image)x direction of an axis(math image)}

  • \pgfplotstransformdirectiony{(math image)y direction of an axis(math image)}

  • \pgfplotstransformdirectionz{(math image)z direction of an axis(math image)}

  • Defines \pgfmathresult to be a low-level pgf direction vector component.

    A direction vector needs to be added to some coordinate in order to get a coordinate, compare the documentation for \pgfplotspointaxisdirectionxy and axis direction cs.

    The argument (math image)x direction of an axis(math image) is processed in (almost) the same way as for the macro which operates on absolute positions, \pgfplotstransformcoordinatex. The only difference is that directions need no shifting transformation.

    The result of this command is also available as math method transformdirectionx (see the documentation for axis direction cs).

    See axis direction cs for details and examples about this command.

  • \pgfplotspointunitx

  • \pgfplotspointunity

  • \pgfplotspointunitz

  • Low-level point commands which return the canvas \(x\), \(y\) or \(z\) unit vectors.

    The \pgfplotspointunitx is the pgf unit vector in \(x\) direction.

    These vectors are essentially the same as \pgfqpointxyz{1}{0}{0}, \pgfqpointxyz{0}{1}{0}, and \pgfqpointxyz{0}{0}{1}, respectively.

    The unit \(z\) vector is only defined for three dimensional axes.

  • \pgfplotsunitxlength

  • \pgfplotsunitylength

  • \pgfplotsunitzlength

  • \pgfplotsunitxinvlength

  • \pgfplotsunityinvlength

  • \pgfplotsunitzinvlength

  • Macros which expand to the vector length \(\lVert x_i \rVert \) of the respective unit vector \(x_i\) or the inverse vector length, \(1/\lVert x_i \rVert \). These macros can be used inside of \pgfmathparse, for example.

    The \(x_i\) are the \pgfplotspointunitx variants.

  • \pgfplotsqpointoutsideofaxis{(math image)three-char-string(math image)}{(math image)coordinate(math image)}{(math image)normal distance(math image)}

  • Provides a point coordinate on one of the available four axes in case of a two dimensional figure or on one of the available twelve axes in case of a three dimensional figure.

    The desired axis is uniquely identified by a three character string, provided as first argument to the command. The first of the three characters is ‘0’ if the \(x\)-coordinate of the specified axis passes through the lower axis limit. It is ‘1’, if the \(x\)-coordinate of the specified axis passes through the upper axis limit. Furthermore, it is ‘2’ if it passes through the origin. The second character is also either 0, 1 or 2 and it characterizes the position on the \(y\)-axis. The third character is for the third dimension, the \(z\)-axis. It should be left at ‘0’ for two dimensional plots. However, one of the three characters should be ‘v’, meaning the axis varies. For example, v01 denotes \(\{ (x,y_{\min },z_{\max }) \vert x \in \mathbb {R} \}\).

    The second argument, (math image)coordinate(math image) is the logical coordinate on that axis. Since two coordinates of the axis are fixed, (math image)coordinate(math image) refers to the varying component of the axis. It must be a number without unit; no math expressions are supported here.

    The third argument (math image)normal distance(math image) is a dimension like 10pt. It shifts the coordinate away from the designated axis in direction of the outer normal vector. The outer normal vector always points away from the axis. It is computed using \pgfplotspointouternormalvectorofaxis.

    There are several variants of this command which are documented in the source code. One of them is particularly useful:

  • \pgfplotsqpointoutsideofaxisrel{(math image)three-char-string(math image)}{(math image)axis fraction(math image)}{(math image)normal distance(math image)}

  • This point coordinate is a variant of \pgfplotsqpointoutsideofaxis which allows to provide an (math image)axis fraction(math image) instead of an absolute coordinate. The fraction is a number between \(0\) (lower axis limit) and \(1\) (upper axis limit), i.e. it is given in percent of the total axis. It is possible to provide negative values or values larger than one.

    The \pgfplotsqpointoutsideofaxisrel command is similar in spirit to rel axis cs.

    There is one speciality in conjunction with reversed axes: if the axis has been reversed by x dir=reverse and, in addition, allow reversal of rel axis cs is true, the value \(0\) denotes the upper limit while \(1\) denotes the lower limit. The effect is that coordinates won’t change just because of axis reversal.

  • \pgfplotspointouternormalvectorofaxis{(math image)three-char-string(math image)}

  • A point command which yields the outer normal vector of the respective axis. The normal vector has length \(1\) (computed with \pgfpointnormalised). It is the same normal vector used inside of \pgfplotsqpointoutsideofaxis and its variants.

    The output of this command will be cached and reused during the lifetime of an axis.

  • \pgfplotsticklabelaxisspec{(math image)x, y or z(math image)}

  • Expands to the three character identification for the axis containing tick labels for the chosen axis, either (math image)x(math image), (math image)y(math image) or (math image)z(math image).

  • \pgfplotsvalueoflargesttickdimen{(math image)x, y or z(math image)}

  • Expands to the largest distance of a tick position to its tick label bounding box in direction of the outer unit normal vector. It does also include the value of the ticklabel shift key.

    This value is used for ticklabel cs.

  • \pgfplotsmathfloatviewdepthxyz{(math image)x(math image)}{(math image)y(math image)}{(math image)z(math image)}

  • \pgfplotsmathviewdepthxyz{(math image)x(math image)}{(math image)y(math image)}{(math image)z(math image)}

  • Both macros define \pgfmathresult to be the “depth” of a three dimensional point \(\bar x = (x,y,z)\). The depth is defined to be the scalar product of \(\bar x\) with \(\vec d\), the view direction of the current axis.

    For \pgfplotsmathfloatviewdepthxyz, the arguments are parsed as floating point numbers and the result is encoded in floating point. A fixed point representation can be generated with \pgfmathfloattofixed{\pgfmathresult}.

    For \pgfplotsmathviewdepthxyz, arithmetics is employed for the inner product and the result is assigned in fixed point. This is slightly faster, but has considerably smaller data range.

    Both commands can only be used inside of a three dimensional pgfplots axis (as soon as the axis is initialised, see \pgfplotsextra).

  • \ifpgfplotsthreedim(math image)true code(math image)\else(math image)else code(math image)\fi

  • A \if which evaluates the (math image)true code(math image) if the axis is three dimensional and the (math image)else code(math image) if not.