tikz.dev / PGFplots Manual

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

The Reference

\(\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}}}\)

4.25Miscellaneous Options

  • /pgfplots/disablelogfilter=true|false (initially false, default true)

  • Disables numerical evaluation of \(\log (x)\) in . If you specify this option, any plot coordinates and tick positions must be provided as \(\log (x)\) instead of \(x\). This may be faster and (possibly) more accurate than the numerical log. The current implementation of \(\log (x)\) normalizes \(x\) to \(m\cdot 10^e\) and computes

    \[ \log (x) = \log (m) + e \log (10) \]

    where \(y = \log (m)\) is computed with a Newton method applied to \(\exp (y) - m\). The normalization involves string parsing without registers. You can safely evaluate \(\log (1\cdot 10^{-7})\) although registers would produce an underflow for such small numbers.

  • /pgfplots/disabledatascaling=true|false (initially false, default true)

  • Disables internal re-scaling of input data. Normally, every input data like plot coordinates, tick positions or whatever, are parsed without using ’s limited number precision. Then, a transformation like

    \[ T(x) = 10^{q-m} \cdot x - a \]

    is applied to every input coordinate/position where \(m\) is “the order of \(x\)” base \(10\). Example: \(x=1234 = 1.234\cdot 10^3\) has order \(m=4\) while \(x=0.001234 = 1.234\cdot 10^{-3}\) has order \(m=-2\). The parameter \(q\) is the order of the axis’ width/height.

    The effect of the transformation is that your plot coordinates can be of arbitrary magnitude like \(0.0000001\) and \(0.0000004\). For these two coordinates, pgfplots will use 100pt and 400pt internally. The transformation is quite fast since it relies only on period shifts. This scaling allows precision beyond ’s capabilities.

    The option “disabledatascaling” disables this data transformation. This has two consequences: first, coordinate expressions like ((math image)axis cs:x,y(math image)) have the same effect as ((math image)x,y(math image)), no re-scaling is applied. Second, coordinates are restricted to what can handle.75

    So far, the data scale transformation applies only to normal axes (logarithmic scales do not need it).

  • /pgfplots/execute at begin plot={(math image)commands(math image)}

  • This axis option allows to invoke (math image)commands(math image) at the beginning of each \addplot command. The argument (math image)commands(math image) can be any content.

    You may use this in conjunction with x filter=... to reset any counters or whatever. An example would be to change every \(4\)th coordinate.

  • /pgfplots/execute at end plot={(math image)commands(math image)}

  • This axis option allows to invoke (math image)commands(math image) after each \addplot command. The argument (math image)commands(math image) can be any content.

  • /pgfplots/execute at begin axis={(math image)commands(math image)}

  • Allows to invoke (math image)commands(math image) at the end of \begin{axis} (or the other “begin axis” statements).

    The statement is executed as (almost) last statement before the preparation has been completed.

  • /pgfplots/visualization depends on=(math image)\macro(math image) (initially empty)

  • /pgfplots/visualization depends on=(math image)expression(math image)\as(math image)\macro(math image) (initially empty)

  • /pgfplots/visualization depends on=value (math image)content(math image)\as(math image)\macro(math image) (initially empty)

  • Allows to communicate data to pgfplots which is essential to perform the visualization although pgfplots isn’t aware of it.

    Suppose you want a scatter plot, which depends on the \((x,y)\) coordinates, the point meta data to draw individual colors and furthermore data which influences the mark size. Thus, you need a total of \(4\) coordinates for every data point, although pgfplots supports only \(3\) in its initial configuration.

    Before we actually come to the main point of the problem, we’ll talk about how to get a scatter plot which has individual colors and individual sizes. It is not sufficient to set mark size alone, since mark size is evaluated only once, before markers are processed (the same holds for every mark). Thus, we can use scatter combined with

    scatter/@pre marker code/.append style={/tikz/mark size=\perpointmarksize}.

    The @pre marker code is installed for every marker of a scatter plot individually. Now, we come to the problem as such: where can we get the value for mark size, in our case called \perpointmarksize?

    A solution is visualization depends on (using the second input syntax at this point):

    (-tikz- diagram)

    % Preamble: \pgfplotsset{width=7cm,compat=1.18} \begin{tikzpicture} \begin{axis} \addplot+ [ scatter, scatter src=y, samples=40, visualization depends on= {5*cos(deg(x)) \as \perpointmarksize}, scatter/@pre marker code/.append style= {/tikz/mark size=\perpointmarksize}, ] {sin(deg(x))}; \end{axis} \end{tikzpicture}

    Here, we define \perpointmarksize as 5*cos(deg(x)). The expression will be evaluated together with all other coordinates. Thus, everything which is available during the survey phase can be used here. This includes the final coordinates x, y, z; the constant meta expands to the current per point meta data. Furthermore, \thisrow{(math image)colname(math image)} expands to the value of a table column.

    The command visualization depends on evaluates and remembers every value in internal data structures. The remembered value is then available as (math image)\macro(math image) during the visualization phase. In our example, the @pre marker code is evaluated during the visualization phase and applies mark size=5*cos(deg(x)).

    The first syntax, visualization depends on=(math image)\macro(math image), tells pgfplots to use an already defined (math image)\macro(math image). The second syntax with (math image)content(math image)\as(math image)\macro(math image) provides also the value.

    There can be more than one visualization depends on phrase.

    In case the stored value is not of numerical type,77 you can use the prefix ‘value’ before the argument, i.e.

    visualization depends on=value (math image)\macro(math image) or

    visualization depends on=value (math image)content(math image)\as (math image)\macro(math image).

    Such a value will be expanded and stored, but not parsed as number (at least not by pgfplots).

  • /pgf/fpu={(math image)true,false(math image)} (initially true)

  • This key activates or deactivates the floating point unit. If it is disabled (false), the core pgf math engine written by Mark Wibrow and Till Tantau will be used for \addplot expression. However, this engine has been written to produce graphics and is not suitable for scientific computing. It is limited to fixed point numbers in the range \(\pm 16384.00000\).

    If the fpu is enabled (true, the initial configuration) the high-precision floating point library of pgf written by Christian Feuersänger will be used. It offers the full range of IEEE double precision computing in . This FPU is also part of PgfplotsTable, and it is activated by default for create col/expr and all other predefined mathematical methods.

    Use

    \pgfkeys{/pgf/fpu=false}

    in order to de-activate the extended precision. If you prefer using the fp (fixed point) package, possibly combined with Mark Wibrows corresponding pgf library, the fpu will be deactivated automatically. Please note, however, that fp has a smaller data range (about \(\pm 10^{17}\)) and may be slower.

75 Please note that the axis’ scaling requires to compute \(1/( x_{\max } - x_{\min } )\). The option disabledatascaling may lead to overflow or underflow in this context, so use it with care! Normally, the data scale transformation avoids this problem.

76 This example from the game theory was provided by Pavel Stříž.

77 Or if it is just a constant and you’d like to improve speed.