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.113D Axis Configuration

This section described keys which are used to configure the appearance of three dimensional figures. Some of them apply for two-dimensional plots as special case as well, and they will also be discussed in the respective sections of this manual.

4.11.1View Configuration
  • /pgfplots/view={(math image)azimuth(math image)}{(math image)elevation(math image)} (initially {25}{30})

  • Changes both view angles of a 3D axis. The azimuth (first argument) is the horizontal angle which is rotated around the \(z\)-axis. For a 3D plot, the \(z\)-axis always points to the top. The elevation (second argument) is the vertical rotation around the (rotated) \(x\)-axis. Positive elevation values indicate a view from above, negative a view from below. All values are measured in degree (but see trig format).

    (-tikz- diagram)

    % Preamble: \pgfplotsset{width=7cm,compat=1.18} \begin{tikzpicture} \begin{axis}[ view={0}{0}, xlabel=$x$, zlabel=$z$, title=View along the positive $y$-axis, ] \addplot3 [surf] {x}; \end{axis} \end{tikzpicture}

    (-tikz- diagram)

    % Preamble: \pgfplotsset{width=7cm,compat=1.18} \begin{tikzpicture} \begin{axis}[ view={0}{90}, xlabel=$x$, ylabel=$y$, title=View from top, ] \addplot3 [surf] {x}; \end{axis} \end{tikzpicture}

    (-tikz- diagram)

    % Preamble: \pgfplotsset{width=7cm,compat=1.18} \begin{tikzpicture} \begin{axis}[ view={-45}{45}, xlabel=$x$, ylabel=$y$, zlabel=$z$, ] \addplot3 [surf] {x}; \end{axis} \end{tikzpicture}

    The view is computed as follows. The view is defined by two rotations: the first rotation uses the (math image)azimuth(math image) angle to rotate around the \(z\) axis. Afterwards, the view is rotated (math image)elevation(math image) degrees around the rotated \(x\)-axis (more precisely, it is rotated \(-\)(math image)elevation(math image) degrees). The resulting transformed \(xz\)-plane is the viewport, i.e. the view direction is always the transformed positive \(y\)-axis.

    The view argument is compatible with the argument of the Matlab® view command, i.e. you can use

    [h,v] = view

    in Matlab and pack the resulting arguments into pgfplots.58

    If you work with gnuplot, you can convert the view arguments as follows: the gnuplot command

    set view v,h

    is equivalent to view={h}{90-v}. For example, the default gnuplot configuration set view 60,60 is equivalent to view={60}{30} in pgfplots.

    The view is (currently) always an orthogonal projection, no perspective is possible, yet. You can, however, specify projection unit vectors for x, y, and z explicitly to get a skewed three-dimensional axis.

  • /pgfplots/view/el={(math image)elevation(math image)}

  • /pgfplots/view/v={(math image)elevation(math image)} (initially 30)

  • Changes only the vertical elevation, i.e. the second argument to view. Positive values view from above, negative values from below.

58 In case it does not work, try h and -v in pgfplots.

4.11.2Styles Used Only For 3D Axes
  • /pgfplots/every 3d description(style, no value)

  • This style allows to change the appearance of descriptions for three dimensional axes. Naturally, a three dimensional axis will display axis labels for \(x\) and \(y\) differently than a two dimensional axis (for example, the \(y\)-axis label won’t be rotated by 90 degrees). The every 3d description style installs the necessary display options for three dimensional axis descriptions.

    The initial value is:

    \pgfkeys{ /pgfplots/every 3d description/.style={ % Only these description styles can be changed here: every axis x label/.style={ at={(ticklabel cs:0.5)}, anchor=near ticklabel, }, every axis y label/.style={ at={(ticklabel cs:0.5)}, anchor=near ticklabel, }, every x tick scale label/.style={ at={(xticklabel cs:0.95,5pt)}, anchor=near xticklabel, inner sep=0pt, }, every y tick scale label/.style={ at={(yticklabel cs:0.95,5pt)}, anchor=near yticklabel, inner sep=0pt, }, try min ticks=3, }, }

    As the name suggests, every 3d description can only be used to set styles for axis labels, tick labels and titles. It has not been designed to reset other styles, you will need to change these options either for each axis separately or by means of user defined styles. The reason for this limitation is: other options can (and, in many cases, needs to) be set before the axis is processed. However, the decision whether we have a two dimensional or a three dimensional axis has to be postponed until the processing is more or less complete – so only some remaining keys can be set.

  • /pgfplots/every 3d view {(math image)h(math image)}{(math image)v(math image)}(style, no value)

  • A style which can be used for fine-tuning of the output for specific views.

    This style will be installed right after every 3d description, but before other axis description related keys are set (in other words: it has higher precedence than every 3d description, but lower precedence than keys provided to the axis directly).

    One example is pre-configured for view={0}{90} (from top):

    \pgfplotsset{ /pgfplots/every 3d view {0}{90}/.style={ xlabel near ticks, ylabel near ticks, axis on top=true, }, }
4.11.3Appearance Of The 3D Box

59 Note that you can also use the syntax {1}{1}{1} instead of space-separation.

4.11.4Axis Line Variants

Three dimensional axes also benefit from the axis lines=box or axis lines=center styles discussed in Section 4.9.9. The choice axis lines=box is standard, it draws a box (probably affected by the 3d box=complete key). The choice axis lines=center draws all three axes such that they pass through the origin. It might be necessary to combine this key with axis on top as there is no depth information.

(-tikz- diagram)

% Preamble: \pgfplotsset{width=7cm,compat=1.18} % Attention: use compat=1.8 or higher % to repair label positions \begin{tikzpicture} \begin{axis}[ axis lines=center, axis on top, samples=5, domain=-4:4, xtick=data, ytick=data, ztick=\empty, % no z ticks here ] \addplot3 [surf] {x*y}; \end{axis} \end{tikzpicture}

The remaining choices axis lines*=left and axis lines*=right select different sets of axes in a way such that tick labels and axis label won’t disturb the plot’s content. The ‘*’ suppresses the use of special styles which are mainly adequate for two-dimensional axes, see the documentation of axis lines. Such a set of axes is always on the boundary of the two-dimensional projection.

The choice axis lines*=left chooses a set of axes which are on the left (or bottom, respectively) whereas the choice axis lines*=right chooses a set of axes which are on the right (or top, respectively):

(-tikz- diagram)

% Preamble: \pgfplotsset{width=7cm,compat=1.18} \begin{tikzpicture} \begin{axis}[ axis lines*=left, samples=5, domain=-4:4, xtick=data, ytick=data, ] \addplot3 [surf] {x*y}; \end{axis} \end{tikzpicture}

(-tikz- diagram)

% Preamble: \pgfplotsset{width=7cm,compat=1.18} \begin{tikzpicture} \begin{axis}[ axis lines*=right, samples=5, domain=-4:4, xtick=data, ytick=data, ] \addplot3 [surf] {x*y}; \end{axis} \end{tikzpicture}

It is not possible to mix different styles like axis x line=center,axis z line=top.