tikz.dev / PGFplots Manual

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

Memory and Speed considerations

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

7.3Reducing Typesetting Time

pgfplots does a lot of computations ranging from abstract coordinate computations to low level .pdf drawing commands (implemented by pgf). For complex plots, this may take a considerable time – especially for 3D plots.

7.3.1LUA

If you use compat=1.12 (or newer) and compile your documents by means of lualatex, pgfplots activates its lua backend. This switch reduces the time to generate output files, especially for 3D plots.

  • /pgfplots/lua backend=true|false (initially true)

  • If lua backend is active and the document is processed by means of lualatex, pgfplots activates scalability and performance improvements which result in the same output as without it, but with less time and with a smarter memory management.

    The feature relies on a partial reimplementation of pgfplots in the fast scripting language lua. In order to benefit from it, you need to

    • 1. write compat=1.12 (or newer) into your preamble and

    • 2. use lualatex to translate your .tex files (or at least those which contain pgfplots figures).

    The time to generate surface plots with this feature can be reduced to 25%–50% of the time required by the pure implementation (i.e. pdflatex). Other plot types will also benefit from the feature.

    The lua backend works in two ways: first, it substitutes isolated routines by faster lua pendants. This is relatively generic. Second, it replaces entire processing steps by an equivalent lua implementation.114 pgfplots 1.12 comes with lua implementations for important and long-running operations. This implementation will be used whenever possible. However, it only covers parts of the feature set: some features of pgfplots are unsupported by the lua backend. In this case, it will be switched off automatically and the implementation will be used as fallback.

    The lua backend will be extended in order to gain more performance improvements and in order to cover more features. Please take a look at lua debug if you want to see if lua backend has been (de)activated for your figure.

    Note that the lua backend uses a different math engine with a higher accuracy. As a consequence, the appearance of a plot might have insignificant pixel differences compared to the output generated by pdflatex. It is generally recommended to stick with one way to generate a document, i.e. to use either lualatex or pdflatex. Migrating from one to another might change the appearance of your document due to lua backend.

    Eventually, pgfplots might add computationally expensive features which can be implemented as part of lua backend and which will be unavailable without it.

    Note that lua backend requires a distribution which supports at least lua 5.2 (like Live 2014). It will be deactivated automatically if your version of lualatex is shipped with an older lua interpreter.

    Here are some guidelines how to benefit from lua backend:

  • /pgfplots/lua debug(no value)

  • /pgfplots/lua debug=false|off|off and silent|verbose|compileerror

  • Typically, the lua backend works silently: pgfplots decides if it is active and if it supports the current operation and proceeds accordingly. If both conditions are satisfied, it will transfer control to the lua backend. If one of them is not met, it will automatically fall back to the old implementation. As a consequence, it cannot be sensed right away, only the time to compile pictures will vary.

    This key controls how pgfplots handles the case where the lua backend is active, but cannot be used because some encountered feature is unsupported.

    The choices false and off deactivate lua debugging. In this case, pgfplots will only write log messages if it used the implementation instead of the lua backend. In addition, it will only write the messages into the .log file (but not into the console output).

    The choice off and silent writes neither information messages nor debug messages: it is the same as off but without the log message if the implementation has been used. It is the least verbose choice.

    The choice verbose will also write success messages into the .log file (not into the console).

    The choice compileerror will abort compilation if the lua backend is active but does not support the current figure or plot.

    Note that pgfplots might come with limited expensive operations which are only available in the lua backend. These items will result in compile errors if the lua backend cannot be used for some reason.

114  An example for the first way is: every time pgfplots makes a lookup in its colormap it transfers control over to the luabackend and the result is immediately communicated back to . The main control flow resides in the slow implementation. An example for the second way is \addplot expression: pgfplots will copy the math expression and any related input arguments (including samples and domain) over to the lua backend. Then, the lua backend will apply all loops and collect coordinates which are finally handed over to the () implementation of pgf. Thus, the control flow resides in the fast lua interpreter.

7.3.2Compiling Images Just Once

One possibility to reduce typesetting time is to tell pgf to generate single, temporary .pdf (or .eps) documents for a subset (or all) graphics in one run and reuse these temporary images in successive runs. For pgfplots, this is the most effective way to reduce typesetting time for larger documents. It can be accomplished using the external library described in Section 8.1.