tikz.dev / PGFplots Manual

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

Related Libraries

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

5.1Clickable Plots

  • \usepgfplotslibrary{clickable} % and plain

  • \usepgfplotslibrary[clickable] % Cont

  • \usetikzlibrary{pgfplots.clickable} % and plain

  • \usetikzlibrary[pgfplots.clickable] % Cont

  • A library which generates small popups whenever one clicks into a plot. The popup displays the coordinate under the mouse pointer, supporting the optional “snap to nearest” clickable coords feature with customizable displayed information. Furthermore, the library allows to display slopes if one holds the mouse pressed and drags it to another point in the plot.

    The library has two purposes: to compute slopes in a simple way80 and to provide related, optional information to single data points which are not important enough to be listed in the main text (like prototype parameters or other technical things).

80 The author is applied mathematician…

5.1.1Overview

It is completely sufficient to write

in the document preamble. This will automatically prepare every plot.

The library works with Acrobat JavaScript and pdf forms: every plot becomes a push button.

(image)    (image)

These screenshots show the result of clicking into the axis range (left column) and of dragging from one point to another (right column). The second case shows the result of Drag-and-Drop: it displays start and end points and the equation for the line segment between between the first point of the drag and drop and the second point where the mouse has been released. The line segment is

\[ l(x; x_0,y_0,x_1,y_1) = m \cdot x + n \]

where \(m = (y_1-y_0) / (x_1-x_0)\) is the slope and \(n\) the offset chosen such that \(l(x_0;\dotsc ) = y_0\). For logarithmic plots, logarithms will be applied before computing slopes.

(image) (image)

These screen shots show the result of drag- and drop for logarithmic axes: the end points show, again, the coordinates (without logs) and the form field in the middle shows the slope and offset of the linear equation in log coordinates.

The log basis for any logarithmic axes is usually \(10\), but it respects the current setting of log basis x and log basis y. The applied log will always use the same logarithm which is also used for the axis descriptions (this is not necessarily the same as used by PgfplotsTable!).

This document has been produced with the clickable library, so it is possible to load it into Acrobat Reader and simply click into a plot.

81 See the PgfplotsTable manual for details about number printing.

5.1.2Requirements for the Library
  • The library relies on the packages insdljs (“Insert document level JavaScript”) and eforms which are both part of the freely available AcroTeX education bundle [6].82 The insdljs package creates a temporary file with extension .djs.

  • At the time of this writing, only Adobe Acrobat Reader interprets JavaScript and Forms properly. The library doesn’t have any effect if the resulting document is used in other viewers (as far as I know).

Note that although this library has been written for pgfplots, it can be used independently of a pgfplots environment.

Compatibility issues:

There a several restrictions when using this library. Most of them will vanish in future versions – but up to now, I can’t do magic.

  • The library does not yet support rotated axes. Use clickable=false for those axes.

  • The library works only with pdflatex; dvips or dvipdfm are not supported.83

  • Up to now, it is not possible to use this library together with the external library and other image externalization methods of Chapter 8.

    To be more precise, you can (with two extra preamble lines, see below) get correctly annotated, exported pdf documents, but the \includegraphics command does not import the dynamic features.

    In case you decide to use this workaround, you need to insert

    % \maxdeadcycles=10000 % in case you get the error `Output loop--- consecutive dead cycles.' \usepackage[pdftex]{eforms}

    before loading pgf, TikZ or pgfplots. The \maxdeadcycles appears to be necessary for large documents, try it out.

    As long as you are working on a draft version of your document, you might want to use

    \pgfkeys{/pgf/images/include external/.code={\href{file:#1}{\pgfimage{#1}}}}

    in your preamble. This will generate hyperlinks around the graphics files which link to the exported figures. Clicking on the hyperlinks opens the exported figure which, in turn, has been generated with the clickable library and allows dynamic features.84

  • The library automatically calls \begin{Form} at \begin{document} and \end{Form} at the end of the document. This environment of hyperref is necessary for dynamic user interaction and should be kept in mind if the document contains other form elements.

Acknowledgements:

  • I have used a JavaScript sprintf implementation of Kevin van Zonneveld [8] (the JavaScript API has only a limited set of conversions).

82 These packages rely on , so the library is only available for , not for plain or Cont.

83 In fact, they should be. I don’t really know why they don’t. Any hint is welcome.

84 This special treatment needs the external files in the same base directory as the main document, so this approach is most certainly not suitable for a final document.

5.1.3Customization

It is possible to customize the library with several options.

  • /pgfplots/clickable=true|false (initially true)

  • Allows to disable the library for single plots.

  • /pgfplots/annot/js fillColor={(math image)JavaScript color(math image)} (initially ["RGB",1,1,.855])

  • Sets the background (fill) color of the short popup annotations.

    Possible choices are transparent, gray, RGB or CMYK color specified as four element arrays of the form ["RGB", (math image)red(math image),(math image)green(math image),(math image)blue(math image)]. Each color component is between \(0\) and \(1\).

    Again: this option is for JavaScript. It is not possible to use colors as in pgf.

  • /pgfplots/annot/point format={(math image)sprintf-format(math image)} (initially (%.1f,%.1f))

  • /pgfplots/annot/point format 3d={(math image)sprintf-format(math image)} (initially (%.1f,%.1f,%.1f))

  • Allows to provide an sprintf format string which is used to fill the annotations with text. The first argument to sprintf is the \(x\)-coordinate and the second argument is the \(y\)-coordinate.

    The point format 3d variant is used for any three-dimensional axis whereas the point format is used (only) for two-dimensional ones.

    The every semilogx axis, every semilogy axis and every loglog axis styles have been updated to

    \pgfplotsset{ every semilogy axis/.append style={/pgfplots/annot/point format={(\% .1f,\%.1e)}}, every semilogx axis/.append style={/pgfplots/annot/point format={(\% .1e,\%.1f)}}, every loglog axis/.append style={/pgfplots/annot/point format={(\% .1e,\%.1e)}}, }

    such that every logarithmic coordinate is displayed in scientific format.

  • /pgfplots/annot/slope format={(math image)sprintf-format(math image)} (initially %.1f*x %+.1f)

  • Allows to provide an sprintf format string which is used to fill the slope annotation with text. The first argument is the slope and the second the line offset.

  • /pgfplots/annot/printable=true|false (initially false)

  • Allows to configure whether the small annotations will be printed. Otherwise, they are only available on screen.

  • /pgfplots/annot/font={(math image)JavaScript font name(math image)} (initially font.Times)

  • Allows to choose a JavaScript font for the annotations. Possible choices are limited to what JavaScript accepts (which is not the same as ). The default fonts and its names are shown below.

    .
    Font Name Name in JavaScript
    Times-Roman font.Times
    Times-Bold font.TimesB
    Times-Italic font.TimesI
    Times-BoldItalic font.TimesBI
    Helvetica font.Helv
    Helvetica-Bold font.HelvB
    Helvetica-Oblique font.HelvI
    Helvetica-BoldOblique font.HelvBI
    Courier font.Cour
    Courier-Bold font.CourB
    Courier-Oblique font.CourI
    Courier-BoldOblique font.CourBI
    Symbol font.Symbol
    ZapfDingbats font.ZapfD
  • /pgfplots/annot/textSize={(math image)Size in Point(math image)} (initially 11)

  • Sets the text size of annotations in points.

  • /pgfplots/annot/popup size generic=auto or {(math image)x(math image)} or {(math image)x,y(math image)} (initially auto)

  • /pgfplots/annot/popup size snap=auto or {(math image)x(math image)} or {(math image)x,y(math image)} (initially auto)

  • /pgfplots/annot/popup size={(math image)value(math image)}

  • The first key defines the size of popups if you just click into an axis. The second key defines the size of popups for the “snap to nearest” feature (i.e. those prepared by clickable coords). The third key sets both to the same (math image)value(math image).

    The argument can be auto in which case pgfplots tries to be smart and counts characters. This may fail for multiline texts. The choice (math image)x(math image) provides the horizontal size only, in units of annot/textSize. Thus, annot/popup size generic=6 makes the popup \(6\cdot 11\) points wide. In this case, only one line will be allocated. Finally, (math image)x,y(math image) allows to provide horizontal and vertical size, both in units of annot/textSize.

    See also clickable coords size which is an alias for annot/popup size snap.

  • /pgfplots/annot/snap dist={(math image)Size in Point(math image)} (initially 4)

  • Defines the size within two mouse clicks are considered to be equivalent, measured in points (Euclidean distance).

  • /pgfplots/annot/richtext=true|false (initially true)

  • Enables or disables richtext formatting in clickable coords arguments. Richtext is kind of XHTML and allows CSS styles like colors, font changes and other CSS attributes, see the documentation for clickable coords for details.

    The case annot/richtext=false is probably more robust.

5.1.4Using the Clickable Library in Other Contexts

This library provides essentially one command, \pgfplotsclickablecreate which creates a clickable area of predefined size, combined with JavaScript interaction code. It can be used independently of pgfplots.

  • \pgfplotsclickablecreate[(math image)required key-value-options(math image)]

  • Creates an area which is clickable. A click produces a popup which contains information about the point under the cursor.

    The complete (!) context needs to be provided using key–value pairs, either set before calling this method of inside of [(math image)required key-value-options(math image)].

    This command actually creates an AcroForm which invokes JavaScript whenever it is clicked. A JavaScript Object is created which represents the context (axis limits and options). This JavaScript object is available at runtime.

    This method is public and it is not restricted to pgfplots. The pgfplots hook simply initializes the required key–value pairs.

    This method does not draw anything. It initializes only a clickable area and JavaScript code.

    The required key–value pairs are documented below.

Attention:

Complete key–value validation is not performed here. It can happen that invalid options will produce JavaScript bugs when opened with Acrobat Reader. Use the JavaScript console to find them.

All options described in the following are only interesting for users who intend to use this library without pgfplots.

  • /pgfplots/annot/width={(math image)dimension(math image)} (initially -)

  • This required key communicates the area’s width to \pgfplotsclickablecreate. It must be a dimension like 5cm.

  • /pgfplots/annot/height={(math image)dimension(math image)} (initially -)

  • This required key communicates the area’s height to \pgfplotsclickablecreate. It must be a dimension like 5cm.

  • /pgfplots/annot/jsname={(math image)string(math image)} (initially -)

  • This required key communicates a unique identifier to \pgfplotsclickablecreate. This identifier is used to identify the object in JavaScript, so there can’t be more than one of them. If it is empty, a default identifier will be generated.

  • /pgfplots/annot/xmin={(math image)number(math image)}

  • /pgfplots/annot/xmax={(math image)number(math image)}

  • /pgfplots/annot/ymin={(math image)number(math image)}

  • /pgfplots/annot/ymax={(math image)number(math image)} (initially empty)

  • These required keys communicate the axis limits to \pgfplotsclickablecreate. They should be set to numbers which can be assigned to a JavaScript floating point number (standard IEEE double precision).

  • /pgfplots/annot/collected plots={(math image)nested arrays(math image)} (initially empty)

  • The low level interface to implement a “snap to nearest” feature. The value is an array of plots, where each plot is again an array of coordinates and each coordinate is an array of three elements, \(x\), \(y\) and text. Please consult the code comments for details and examples.