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.7Markers, Linestyles, (Background) Colors and Colormaps

The following options of TikZ are available to plots.

4.7.1Markers

This list is copied from the PGF/TikZ manual (Section 29).

  • mark=* (-tikz- diagram)

  • mark=x (-tikz- diagram)

  • mark=+ (-tikz- diagram)

And with \usetikzlibrary{plotmarks}:

  • mark=\(-\) (-tikz- diagram)

  • mark=\(\vert \) (-tikz- diagram)

  • mark=o (-tikz- diagram)

  • mark=asterisk (-tikz- diagram)

  • mark=star (-tikz- diagram)

  • mark=10-pointed star (-tikz- diagram)

  • mark=oplus (-tikz- diagram)

  • mark=oplus* (-tikz- diagram)

  • mark=otimes (-tikz- diagram)

  • mark=otimes* (-tikz- diagram)

  • mark=square (-tikz- diagram)

  • mark=square* (-tikz- diagram)

  • mark=triangle (-tikz- diagram)

  • mark=triangle* (-tikz- diagram)

  • mark=diamond (-tikz- diagram)

  • mark=diamond* (-tikz- diagram)

  • mark=halfdiamond* (-tikz- diagram)

  • mark=halfsquare* (-tikz- diagram)

  • mark=halfsquare right* (-tikz- diagram)

  • mark=halfsquare left* (-tikz- diagram)

  • mark=Mercedes star (-tikz- diagram)

  • mark=Mercedes star flipped (-tikz- diagram)

  • mark=halfcircle (-tikz- diagram)

    One half is filled with white (more precisely, with mark color).

  • mark=halfcircle* (-tikz- diagram)

    One half is filled with white (more precisely, with mark color) and the other half is filled with the actual fill color.

  • mark=pentagon (-tikz- diagram)

  • mark=pentagon* (-tikz- diagram)

  • mark=ball (-tikz- diagram)

    This marker is special and can easily generate big output files if there are lots of them. It is also special in that it needs ball color to be set (in our case, it is ball color=yellow!80!black.

  • mark=text (-tikz- diagram)

    This marker is special as it can be configured freely. The character (or even text) used is configured by a set of variables, see below.

  • mark=cube (-tikz- diagram)

    This marker is only available inside of a pgfplots axis, it draws a cube with axis parallel faces. Its dimensions can be configured separately, see below.

  • mark=cube* (-tikz- diagram)

  • User defined It is possible to define new markers with \pgfdeclareplotmark, see below.

All these options have been drawn with the additional options

\draw [ gray, thin, mark options={ scale=2,fill=yellow!80!black,draw=black, }, ]

Please see Section 4.7.5 for how to change draw and fill colors. Note that each of the provided marks can be rotated freely by means of mark options={rotate=90} or every mark/.append style={rotate=90}.

  • /tikz/mark size={(math image)dimension(math image)} (initially 2pt)

  • This TikZ option allows to set marker sizes to (math image)dimension(math image). For circular markers, (math image)dimension(math image) is the radius, for other plot marks it is about half the width and height.

  • /pgfplots/cube/size x={(math image)dimension(math image)} (initially \pgfplotmarksize=2pt)

  • /pgfplots/cube/size y={(math image)dimension(math image)} (initially \pgfplotmarksize=2pt)

  • /pgfplots/cube/size z={(math image)dimension(math image)} (initially \pgfplotmarksize=2pt)

  • Sets the size for mark=cube separately for every axis.

  • /pgfplots/no markers(style, no value)

  • A key which overrides any mark value set by cycle list of option lists after \addplot.

    If this style is provided as argument to a complete axis, it is appended to every axis plot post such that it disables markers even for cycle lists which contain markers.

  • /tikz/mark repeat={(math image)integer(math image)} (initially empty)

  • Allows to draw only each \(n\)th mark where \(n\) is provided as (math image)integer(math image).

  • /tikz/mark indices={(math image)index list(math image)} (initially empty)

  • Allows to draw only the marker whose index numbers are in the argument list.

  • /pgf/mark color={(math image)color(math image)} (initially empty)

  • Defines the additional fill color for the halfcircle, halfcircle*, halfdiamond* and halfsquare* markers. An empty value uses white (which is the initial configuration). The value none disables filling for this part.

    These markers have two distinct fill colors, one is determined by fill as for any other marker and the other one is mark color.

    (-tikz- diagram)

    % Preamble: \pgfplotsset{width=7cm,compat=1.18} \begin{tikzpicture} \begin{axis}[y=2cm] \addplot [ blue, mark color=blue!50!white, mark=halfcircle* ] coordinates { (-2,0) (-1,1) (0,0) (1,1) (2,0) }; \addplot [ red, mark color=red!50!white, mark=halfsquare*, ] coordinates { (-2,-0.1) (-1,0.9) (0,-0.1) (1,0.9) (2,-0.1) }; \end{axis} \end{tikzpicture}

    Note that this key requires pgf 2.10 or later.

  • /tikz/mark options={(math image)options(math image)}

  • Resets every mark to {(math image)options(math image)}.

  • /pgf/text mark={(math image)text(math image)} (initially p)

  • Changes the text shown by mark=text.

    With /pgf/text mark=m: (-tikz- diagram)

    With /pgf/text mark=A: (-tikz- diagram)

    There is no limitation about the number of characters or whatever. In fact, any material can be inserted as (math image)text(math image), including images.

  • /pgf/text mark style={(math image)options for mark=text(math image)}

  • Defines a set of options which control the appearance of mark=text.

    If /pgf/text mark as node=false (the default), (math image)options(math image) is provided as argument to \pgftext – which provides only some basic keys like left, right, top, bottom, base and rotate.

    If /pgf/text mark as node=true, (math image)options(math image) is provided as argument to \node. This means you can provide a very powerful set of options including anchor, scale, fill, draw, rounded corners, etc.

  • /pgf/text mark as node=true|false (initially false)

  • Configures how mark=text will be drawn: either as \node or as \pgftext.

    The first choice is highly flexible and possibly slow, the second is very fast and usually enough.

  • \pgfdeclareplotmark{(math image)plot mark name(math image)}{(math image)code(math image)}

  • Defines a new marker named (math image)plot mark name(math image). Whenever it is used, (math image)code(math image) will be invoked. It is supposed to contain (preferable pgf basic level) drawing commands. During (math image)code(math image), the coordinate system’s origin denotes the coordinate where the marker shall be placed.

    Please refer to the PGF/TikZ manual section “Mark Plot Handler” for more detailed information.

Markers paths are not subjected to clipping as other parts of the figure. Markers are either drawn completely or not at all.

TikZ offers more options for marker fine tuning, please refer tothe PGF/TikZ manual for details.

4.7.2Line Styles

The following line styles are predefined in TikZ.

  • /tikz/solid(style, no value)

  • (-tikz- diagram)

  • /tikz/dotted(style, no value)

  • (-tikz- diagram)

  • /tikz/densely dotted(style, no value)

  • (-tikz- diagram)

  • /tikz/loosely dotted(style, no value)

  • (-tikz- diagram)

  • /tikz/dashed(style, no value)

  • (-tikz- diagram)

  • /tikz/densely dashed(style, no value)

  • (-tikz- diagram)

  • /tikz/loosely dashed(style, no value)

  • (-tikz- diagram)

  • /tikz/dashdotted(style, no value)

  • (-tikz- diagram)

  • /tikz/densely dashdotted(style, no value)

  • (-tikz- diagram)

  • /tikz/loosely dashdotted(style, no value)

  • (-tikz- diagram)

  • /tikz/dashdotdotted(style, no value)

  • (-tikz- diagram)

  • /tikz/densely dashdotdotted(style, no value)

  • (-tikz- diagram)

  • /tikz/loosely dashdotdotted(style, no value)

  • (-tikz- diagram)

since these styles apply to markers as well, you may want to consider using

in marker styles.

Besides linestyles, pgf also offers (a lot of) arrow heads. Please refer tothe PGF/TikZ manual for details.

4.7.3Edges and Their Parameters

When pgfplots connects points, it relies on pgf drawing parameters to create proper edges (and it only changes them in the every patch style).

It might occasionally be necessary to change these parameters:

4.7.4Font Size and Line Width

Often, one wants to change line width and font sizes for plots. This can be done using the following options of TikZ.

  • /tikz/font={(math image)font name(math image)} (initially \normalfont)

  • Sets the font which is to be used for text in nodes (like tick labels, legends or descriptions).

    A font can be any argument like \footnotesize or \small\bfseries.35

    It may be useful to change fonts only for specific axis descriptions, for example using

    \pgfplotsset{ tick label style={font=\small}, label style={font=\small}, legend style={font=\footnotesize}, }

    See also the predefined styles normalsize, small and footnotesize in Section 4.10.2.

  • /tikz/thin(no value)

  • /tikz/ultra thin(no value)

  • /tikz/very thin(no value)

  • /tikz/semithick(no value)

  • /tikz/thick(no value)

  • /tikz/very thick(no value)

  • /tikz/ultra thick(no value)

  • These TikZ styles provide different predefined line widths.

(-tikz- diagram)

% Preamble: \pgfplotsset{width=7cm,compat=1.18} \pgfplotsset{every axis/.append style={ font=\large, line width=1pt, tick style={line width=0.8pt}}} \begin{tikzpicture} \begin{loglogaxis}[ legend pos=south west, xlabel=\textsc{Dof}, ylabel=$L_2$ Error ] \addplot coordinates { (5,8.312e-02) (17,2.547e-02) (49,7.407e-03) (129,2.102e-03) (321,5.874e-04) (769,1.623e-04) (1793,4.442e-05) (4097,1.207e-05) (9217,3.261e-06) }; \addplot coordinates{ (7,8.472e-02) (31,3.044e-02) (111,1.022e-02) (351,3.303e-03) (1023,1.039e-03) (2815,3.196e-04) (7423,9.658e-05) (18943,2.873e-05) (47103,8.437e-06)}; \addplot coordinates{ (9,7.881e-02) (49,3.243e-02) (209,1.232e-02) (769,4.454e-03) (2561,1.551e-03) (7937,5.236e-04) (23297,1.723e-04) (65537,5.545e-05) (178177,1.751e-05)}; \addplot coordinates{ (11,6.887e-02) (71,3.177e-02) (351,1.341e-02) (1471,5.334e-03) (5503,2.027e-03) (18943,7.415e-04) (61183,2.628e-04) (187903,9.063e-05) (553983,3.053e-05)}; \addplot coordinates{ (13,5.755e-02) (97,2.925e-02) (545,1.351e-02) (2561,5.842e-03) (10625,2.397e-03) (40193,9.414e-04) (141569,3.564e-04) (471041,1.308e-04) (1496065,4.670e-05)}; \legend{$d=2$,$d=3$,$d=4$,$d=5$,$d=6$} \end{loglogaxis} \end{tikzpicture}

The preceding example defines data which is used a couple of times throughout this manual; it is referenced by \plotcoords.

(-tikz- diagram)

% Preamble: \pgfplotsset{width=7cm,compat=1.18} \pgfplotsset{every axis/.append style={ font=\footnotesize, thin, tick style={ultra thin}}, } \begin{tikzpicture} \begin{loglogaxis}[ xlabel=\textsc{Dof}, ylabel=$L_2$ Error ] % see above for this macro: \plotcoords \legend{$d=2$,$d=3$,$d=4$,$d=5$,$d=6$} \end{loglogaxis} \end{tikzpicture}

35 Cont and plain users need to provide other statements, of course.

4.7.5Colors

pgf uses the color support of xcolor. Therefore, the main reference for how to specify colors is the xcolor manual [3]. The PGF/TikZ manual is the reference for how to select colors for specific purposes like drawing, filling, shading, patterns etc. This section contains a short overview over the specification of colors in [3] (which is not limited to pgfplots).

The package xcolor defines a set of predefined colors, namely (-tikz- diagram) red, (-tikz- diagram) green, (-tikz- diagram) blue, (-tikz- diagram) cyan, (-tikz- diagram) magenta, (-tikz- diagram) yellow, (-tikz- diagram) black, (-tikz- diagram) gray, (-tikz- diagram) white, (-tikz- diagram) darkgray, (-tikz- diagram) lightgray, (-tikz- diagram) brown, (-tikz- diagram) lime, (-tikz- diagram) olive, (-tikz- diagram) orange, (-tikz- diagram) pink, (-tikz- diagram) purple, (-tikz- diagram) teal, (-tikz- diagram) violet.

(-tikz- diagram)

% Preamble: \pgfplotsset{width=7cm,compat=1.18} \begin{tikzpicture} \begin{axis}[enlarge x limits=false] \addplot [red,samples=500] {sin(deg(x))}; \addplot [orange,samples=7] {sin(deg(x))}; \addplot [teal,const plot,samples=14] {sin(deg(x))}; \end{axis} \end{tikzpicture}

Besides predefined colors, it is possible to mix two (or more) colors. For example, (-tikz- diagram) red!30!white contains \(30\%\) of (-tikz- diagram) red and \(70\%\) of (-tikz- diagram) white. Consequently, one can build (-tikz- diagram) red!70!white to get \(70\%\) red and \(30\%\) white or (-tikz- diagram) red!10!white for \(10\%\) red and \(90\%\) white. This mixing can be done with any color, for example (-tikz- diagram) red!50!green, (-tikz- diagram) blue!50!yellow or (-tikz- diagram) green!60!black.

A different type of color mixing is supported, which allows to take \(100\%\) of each component. For example, (-tikz- diagram) rgb,2:red,1;green,1 will add \(1/2\) part (-tikz- diagram) red and \(1/2\) part (-tikz- diagram) green and we reproduced the example from above. Using the denominator \(1\) instead of \(2\) leads to (-tikz- diagram) rgb,1:red,1;green,1 which uses \(1\) part (-tikz- diagram) red and \(1\) part (-tikz- diagram) green. Many programs allow to select pieces between \(0,\dotsc ,255\), so a denominator of \(255\) is useful. Consequently, (-tikz- diagram) rgb,255:red,231;green,84;blue,121 uses \(231/255\) red, \(84/255\) green and \(121/255\). This corresponds to the standard RGB color \((231,84,121)\). Other examples are (-tikz- diagram) rgb,255:red,32;green,127;blue,43, (-tikz- diagram) rgb,255:red,178;green,127;blue,43, (-tikz- diagram) rgb,255:red,169;green,178;blue,43.

It is also possible to use RGB values, the HSV color model, the CMY (or CMYK) models, or the HTML color syntax directly. However, this requires some more programming. I suppose this is the fastest (and probably the most uncomfortable) method to use colors. For example,

(-tikz- diagram)

\definecolor{color1}{rgb}{1,1,0} \tikz \fill[color1] (0,0) rectangle (1em,0.6em);

creates the color with \(100\%\) (-tikz- diagram) red, \(100\%\) (-tikz- diagram) green and \(0\%\) (-tikz- diagram) blue;

(-tikz- diagram)

\definecolor{color1}{cmyk}{0.6,0.9,0.5,0.1} \tikz \fill[color1] (0,0) rectangle (1em,0.6em);

creates the color with \(60\%\) (-tikz- diagram) cyan, \(90\%\) (-tikz- diagram) magenta, \(50\%\) (-tikz- diagram) yellow and \(10\%\) (-tikz- diagram) black;

(-tikz- diagram)

\definecolor{color1}{HTML}{D0B22B} \tikz \fill[color1] (0,0) rectangle (1em,0.6em);

creates the color with \(208/255\) pieces red, \(178/255\) pieces green and \(43\) pieces blue, specified in standard HTML notation. Please refer to the xcolor manual [3] for more details and color models.

The xcolor package provides even more methods to combine colors, among them the prefix ‘-’ (minus) which changes the color into its complementary color ((-tikz- diagram) -black, (-tikz- diagram) -white, (-tikz- diagram) -red) or color wheel calculations. Please refer to the xcolor manual [3].

  • /tikz/color={(math image)a color(math image)}

  • /tikz/draw={(math image)stroke color(math image)}

  • /tikz/fill={(math image)fill color(math image)}

  • These keys are (generally) used to set colors. Use color to set the color for both drawing and filling. Instead of color={(math image)color name(math image)} you can simply write (math image)color name(math image). The draw and fill keys only set colors for stroking and filling, respectively.

    Use draw=none to disable drawing and fill=none to disable filling.36

    Since these keys belong to TikZ, the complete documentation can be found in the PGF/TikZ manual, Section “Specifying a Color”.

36 Up to now, plot marks always have a stroke color (some also have a fill color). This restriction may be lifted in upcoming versions.

4.7.5.1Color Spaces

Since pgfplots relies on xcolor, all mechanisms of xcolor to define color spaces apply here as well.

One of the most useful approaches is global color space conversion: if you want a document which contains only colors in the cmyk color spaces, you can say

\usepackage[cmyk]{xcolor} \usepackage{pgfplots}

in order to convert all colors of the entire document (including all shaded) to cmyk.

The same can be achieved by means of the xcolor statement \selectcolormodel.

4.7.6Color Maps

A “color map” is a sequence of colors with smooth transitions between them. Color maps are often used to visualize “color data” in plots: in this case, a plot has the position coordinates \((x,y)\) and some additional scalar value (point meta) which can be used as “color data”. The smallest encountered point meta is then mapped to the first color of a colormap, the largest encountered value of point meta is mapped to the last color of a colormap, and interpolation happens in-between.

  • /pgfplots/colormap name={(math image)color map name(math image)} (initially hot)

  • Changes the current color map to the already defined map named (math image)color map name(math image). The predefined color maps are

    .
    viridis
    hot

    The definition can be found in the documentation for colormap/hot and colormap/viridis, respectively. These, and further color maps, are described below.

    Color maps can be used, for example, in scatter plots and surface plots.

    You can use colormap to create new color maps (see below).

  • /pgfplots/colormap={(math image)name(math image)}{(math image)color specification(math image)}

  • Defines a new colormap named (math image)name(math image) according to (math image)color specification(math image) and activates it using colormap name={(math image)name(math image)}.

    A simple (math image)color specification(math image) is just a sequence of color definitions of type

    (math image)color type(math image)=((math image)color value(math image))

    separated by either white spaces or semicolon or comma:

    \pgfplotsset{colormap={CM}{rgb=(0,0,1) color=(black) rgb255=(238,140,238)}}

    Here, the three input colors form the left end, middle point, and right end of the interval, respectively. A couple of (math image)color type(math image)s are available, the (math image)color value(math image) depends on the actual (math image)color type(math image) which is shown below in all detail. Most colormap definitions use the simple form and merely list suitable color definitions.

    A more advanced (math image)color specification(math image) is one which defines both colors and positions in order to define the place of each color. In this case, pgfplots offers the syntax

    (math image)color type(math image)((math image)offset(math image))=((math image)color value(math image)):

    \pgfplotsset{colormap={CM}{rgb(-500)=(0,0,1) color(0)=(black) rgb255(1500)=(238,140,238)}}

    This syntax allows to distribute colors over the interval using nonuniform distances.

Compatibility note:

pgfplots up to and including version \(1.13\) offered just rudimentary support for nonuniform color maps. You need to write compat=1.14 or higher in order to make use of nonuniform color maps.

The positions can be arbitrary numbers (or dimensions),37 but each new color must come with a larger position than its preceding one. The position can be omitted in which case it will be deduced from the context: if the first two colors have no position, the first will receive position \(0\) and the second will receive position “\(1\text {cm}\)”. All following ones receive the last encountered mesh width. Note that nonuniform positions make a real difference in conjunction with colormap access=piecewise const.

The precise input format is described in the following section.

37 Note that pgfplots up to and including version \(1.13\) only supported ranges \([0,16300]\).

4.7.6.1Colormap Input Format Reference

Each entry in (math image)color specification(math image) has the form

(math image)color model(math image)((math image)position(math image))=((math image)arguments(math image)) or

(math image)special mode(math image)((math image)position(math image))=((math image)argument(math image) of (math image)colormap name(math image))

where the most common form is to specify a color using a (math image)color model(math image) like rgb=(0,0.5,1). The (math image)special mode(math image)s are discussed later in Section 4.7.6.4 on page (page for section 4.7.6.4); they are useful to access colors of existing colormaps. The (math image)position(math image) argument is optional and defaults to \(0\) for the first color, \(1\text {cm}\) for the second, and an automatically deduced mesh grid for all following ones. The number range of (math image)position(math image) is arbitrary. Note that pgfplots merely remembers the relative distances of the (math image)positions(math image), not their absolute values. Consequently, a color map with positions \(0,1,2\) is equivalent to one with \(0,10,20\) or \(-10,0,10\) or \(-1100,-1000,-900\). pgfplots maps the input positions to the range \([0,1000]\) internally and works with these numbers. Each new color must have a (math image)position(math image) which is larger than the preceding one.

Available choices for (math image)color model(math image) are

rgb which expects (math image)arguments(math image) of the form ((math image)red(math image),(math image)green(math image),(math image)blue(math image)) where each component is in the interval \([0,1]\),

rgb255 which is similar to rgb except that each component is expected in the interval [0,255],

gray in which case (math image)arguments(math image) is a single number in the interval \([0,1]\),

color in which case (math image)arguments(math image) contains a predefined (named) color like ‘red’ or a color expression like ‘red!50’,

cmyk which expects (math image)arguments(math image) of the form ((math image)cyan(math image),(math image)magenta(math image),(math image)yellow(math image),(math image)black(math image)) where each component is in the interval \([0,1]\),

cmyk255 which is the same as cmyk but expects components in the interval \([0,255]\),

cmy which expects (math image)arguments(math image) of the form ((math image)cyan(math image),(math image)magenta(math image),(math image)yellow(math image)) where each component is in the interval \([0,1]\),

hsb which expects (math image)arguments(math image) of the form ((math image)hue(math image),(math image)saturation(math image),(math image)brightness(math image)) where each component is in the interval \([0,1]\),

Hsb which is the same as hsb except that (math image)hue(math image) is accepted in the interval \([0,360]\) (degree),

HTML which is similar to rgb255 except that each component is expected to be a hex number between 00 and FF,

wave which expects a single wave length as numeric argument in the range \([363,814]\).

(-tikz- diagram)

% Preamble: \pgfplotsset{width=7cm,compat=1.18} \begin{tikzpicture} \begin{axis}[ colormap={bw}{ gray(0cm)=(0); gray(1cm)=(1); }, ] \addplot+ [ scatter, only marks, domain=0:8, samples=100, ] {exp(x)}; \end{axis} \end{tikzpicture}

The choice of (math image)positions(math image) influences the processing time: a uniform distance between the (math image)positions(math image) allows more efficient lookup than nonuniform distances. If there is no visual difference and it does not hurt with respect to the number of data points, prefer color maps with uniform distances over nonuniform maps. Note that nonuniform maps make a huge difference in conjunction with colormap access=piecewise constant. pgfplots provides a simple way to map a nonuniform color definition to a uniform one: write the target mesh width as first item in the specification. pgfplots will perform this interpolation automatically, provided all encountered (math image)positions(math image) can be mapped to the target grid:

% non-uniform spacing example: the mesh width is provided as first % part of the specification. \pgfplotsset{colormap={violetnew} {[1cm] rgb255(0cm)=(25,25,122) color(1cm)=(white) rgb255(5cm)=(238,140,238)}}

In this last example, the mesh width has been provided explicitly and pgfplots interpolates the missing grid points on its own. It is an error if the provided positions are no multiple of the mesh width.

4.7.6.2The Colorspace of a Colormap

Attention: this section is essentially superfluous if you have configured the xcolor package to override color spaces globally (for example by means of \usepackage[cmyk]{xcolor} before loading pgfplots), see the end of this subsection.

Even though a colormap accepts lots of color spaces on input (in fact, it accepts most or all that xcolor provides), the output color of a colorspace has strict limitations. The output colorspace is the one in which pgfplots interpolates between two other colors. To this end, it transforms input colors to the output color space. The output colorspace is also referred to as “the colorspace of a colormap”.

There are three supported color spaces for a colormap: the GRAY, RGB, and CMYK color spaces. Each access into a colormap requires linear interpolation which is performed in its color space. Color spaces make a difference: colors in different color spaces may be represented differently, depending on the output device. Many printers use CMYK for color printing, so providing CMYK colors might improve the printing quality on a color printer. The RGB color space is often used for display devices. The predefined colormaps in pgfplots all use RGB.

Whenever a new colormap is created, pgfplots determines an associated color space. Then, each color in this specific colormap will be represented in its associated color space (converting colors automatically if necessary). Furthermore, every access into the colormap will be performed in its associated color space and every returned mapped color will be represented with respect to this color space. Furthermore, every shading generated by shader=interp will be represented with respect to the colormap’s associated color space.

The color space is chosen as follows: in case colormap default colorspace=auto (the initial configuration), the color space depends on the first encountered color in (math image)color specification(math image). For rgb or gray or color, the associated color space will be RGB (as it was in all earlier versions of pgfplots). For cmyk, the associated color space will be CMYK. If colormap default colorspace is either gray, rgb or cmyk, this specific color space is used and every color is converted automatically.

  • /pgfplots/colormap default colorspace=auto|gray|rgb|cmyk (initially auto)

  • Allows to set the color space of every newly created colormap. The choices are explained in the previous paragraph.

    It is impossible to change the color space of an existing colormap; recreate it if conversion is required.

    The macro \pgfplotscolormapgetcolorspace{(math image)name(math image)} defines \pgfplotsretval to contain the color space of an existing colormap name, if you are in doubt.

    Note that this option has no effect if you told xcolor to override the color space globally. More precisely, the use of

    \usepackage[cmyk]{xcolor}

    or, alternatively,

    will cause all colors to be converted to cmyk, and pgfplots honors this configuration. Consequently, both these statements cause all colors to be interpolated in the desired color space, and all output colors will use this colorspace. This is typically exactly what you need.

4.7.6.3Predefined Colormaps

Available color maps are shown below.

  • /pgfplots/colormap/viridis(style, no value)

  • A style which installs the colormap “viridis” which has been defined by Stèfan van der Walt and Nathaniel Smith for Matplotlib. It is designated to be the default colormap for Matplotlib starting with version 2.0 and is released under the CC038.

    The choice viridis is a downsampled copy included in pgfplots.

    \pgfplotsset{ colormap name=viridis, }

    This colormap has considerably better properties compared to other choices:

    • its color distribution is perceptually uniform (compare the definition in the link below),

    • it is suitable for moderate forms of color blindness,

    • it is still good when printed in black and white.

    Details about these properties can be found in http://bids.github.io/colormap.

    Please use the choice colormap name=viridis as this makes uses of the predefined colormap whereas colormap/viridis will redefine it.

    There is also a high resolution copy of viridis which is called colormap/viridis high res in the colormaps library. It resembles the original resolution of the authors, but it is visually almost identically to viridis and requires less resources in .

  • /pgfplots/colormap/hot(style, no value)

  • A style which installs the colormap

    \pgfplotsset{ colormap={hot}{color(0cm)=(blue); color(1cm)=(yellow); color(2cm)=(orange); color(3cm)=(red)} }

    This is a pre-configured color map.

  • /pgfplots/colormap/hot2(style, no value)

  • A style which is equivalent to

    \pgfplotsset{ /pgfplots/colormap={hot2}{[1cm]rgb255(0cm)=(0,0,0) rgb255(3cm)=(255,0,0) rgb255(6cm)=(255,255,0) rgb255(8cm)=(255,255,255)} }

    Note that this particular choice ships directly with pgfplots, you do not need to load the colormaps library for this value.

    This colormap is similar to one shipped with Matlab® under a similar name.

  • /pgfplots/colormap/blackwhite(style, no value)

  • A style which is equivalent to

    \pgfplotsset{ colormap={blackwhite}{gray(0cm)=(0); gray(1cm)=(1)} }

Remark:

The style bluered (re)defines the color map and activates it. will be slightly faster if you call \pgfplotsset{colormap/bluered} in the preamble (to create the color map once) and use colormap name=bluered whenever you need it. This remark holds for every color map style which follows. But you can simply ignore this remark.

  • /pgfplots/colormap/cool(style, no value)

  • A style which is equivalent to

    \pgfplotsset{ colormap={cool}{rgb255(0cm)=(255,255,255); rgb255(1cm)=(0,128,255); rgb255(2cm)=(255,0,255)} }

  • /pgfplots/colormap/greenyellow(style, no value)

  • A style which is equivalent to

    \pgfplotsset{ colormap={greenyellow}{rgb255(0cm)=(0,128,0); rgb255(1cm)=(255,255,0)} }

  • /pgfplots/colormap/redyellow(style, no value)

  • A style which is equivalent to

    \pgfplotsset{ colormap={redyellow}{rgb255(0cm)=(255,0,0); rgb255(1cm)=(255,255,0)} }

  • /pgfplots/colormap/violet(style, no value)

  • A style which is equivalent to

    \pgfplotsset{ colormap={violet}{rgb255=(25,25,122) color=(white) rgb255=(238,140,238)} }

  • \pgfplotscolormaptoshadingspec{(math image)colormap name(math image)}{(math image)right end size(math image)}{(math image)\macro(math image)}

  • A command which converts a colormap into a pgf shading’s color specification. It can be used in commands like \pgfdeclare...shading (see the PGF/TikZ manual for details).

    The first argument is the name of a (defined) colormap, the second the rightmost dimension of the specification. The result will be stored in (math image)\macro(math image).

    % convert `hot' -> \result \pgfplotscolormaptoshadingspec{hot}{8cm}\result % define and use a shading in pgf: \def\tempb{\pgfdeclarehorizontalshading{tempshading}{1cm}}% % where `\result' is inserted as last argument: \expandafter\tempb\expandafter{\result}% \pgfuseshading{tempshading}%

    The usage of the result (math image)\macro(math image) is a little bit low-level.

Attention:

pgf shadings are always represented with respect to the RGB color space. Consequently, even CMYK (math image)colormap name(math image)s will result in an RGB shading specification when using this method.39

  • \pgfplotscolorbardrawstandalone[(math image)options(math image)]

  • A command which draws a tikzpicture and a colorbar using the current colorbar settings inside of it. Its purpose is to simplify the documentation.

    Since this colorbar is a “standalone” picture, it defines the following options

    point meta min=0, point meta max=1000, parent axis width/.initial=6cm, parent axis height/.initial=6cm,

    before it evaluates (math image)options(math image) and draws the colorbar.

Note that there are more available choices of colormaps in the associated libraries, name in the colorbrewer library and in the colormaps library which need to be loaded by means of \usepgfplotslibrary{colorbrewer,colormaps}.

38 https://creativecommons.org/about/cc0

39 In case pgf should someday support CMYK shadings and you still see this remark, you can add the macro definition \def\pgfplotscolormaptoshadingspectorgb{0} to your preamble.

4.7.6.4Building Colormaps based on other Colormaps

A colormap definition of sorts colormap={(math image)name(math image)}{(math image)color specification(math image)} typically consists of (math image)color specifications(math image) made up from single colors, each with its own (math image)color model(math image). As outlined in Section 4.7.6.1, each entry in (math image)color specification(math image) has the form

(math image)color model(math image)((math image)position(math image))=((math image)arguments(math image)) or

(math image)special mode(math image)((math image)position(math image))=((math image)argument(math image) of (math image)colormap name(math image)).

This section explains how to make use of (math image)special mode(math image) in order to build colormaps based on existing colormaps. To this end, pgfplots offers the following values inside of a (math image)color specification(math image):

  • /pgfplots/colormap access/extra interval width={(math image)fraction(math image)} (initially h)

Attention:

this key is supposed to be a technical part of the implementation. You may want to skip its documentation as it typically works out of the box. You only need to respect sample for.

This key applies only to colormap access=piecewise constant: it ensures that each color in the colormap receives its own interval. This ensures that each color is actually visible in the output. Thus, each provided color resembles an interval. This is different from colormap access=map where each provided color resembles an interval boundary.

Normally, pgfplots, activates this feature if and only if it has automatically computed positions. Consequently, the following example implicitly uses extra interval width=h (the default):

(-tikz- diagram)

\pgfplotscolorbardrawstandalone[ colormap={example}{ color=(blue) color=(red) color=(black) }, colorbar horizontal, colorbar style={xtick=data}, colormap access=const, ]

As soon as you provide positions manually, pgfplots defaults to extra interval width=0 in order to respect the input settings:

(-tikz- diagram)

\pgfplotscolorbardrawstandalone[ colormap={example}{ color(0)=(blue) color(500)=(red) color(1000)=(black) }, colorbar horizontal, colorbar style={xtick=data}, colormap access=const, ]

Note that the positions make up the input nodes for the colormap with the consequence that the last color is unused; it merely serves as interval boundary. In this context, “provide manually” means positions in round braces or a non-empty value of target pos.

In order to override the input positions and get an extra interval, you have to set the option:

(-tikz- diagram)

\pgfplotscolorbardrawstandalone[ colormap={example}{ color(0)=(blue) color(500)=(red) color(1000)=(black) }, colorbar horizontal, colorbar style={xtick=data}, colormap access/extra interval width=h, colormap access=const, ]

Note how the extra interval of colormap access=const modifies the positions of the colormap definition: they are all shifted to the left and the chosen input positions are scaled accordingly. This becomes more apparent in the following example. First, we generate a colormap with the default settings which disables the extra interval, but omits the last (brightest) color:

(-tikz- diagram)

\pgfplotscolorbardrawstandalone[ colormap={nonuniform}{ of colormap={ viridis, target pos={0,200,300,500,700,1000} }, }, colorbar horizontal, colormap access=const, colorbar style={xtick=data,font=\tiny, /pgf/number format/precision=0}, colormap access=const, ]

Next, we explicitly enable the extra interval and see that the input positions are scaled to the left. Note that they keep their relative distances, but the last color of the colormap is finally visible:

(-tikz- diagram)

The last example relies on of colormap and a sampling procedure. In this context, pgfplots offers sample for=const which results in the expected look:

(-tikz- diagram)

\pgfplotscolorbardrawstandalone[ colormap={nonuniform}{ of colormap={ viridis, target pos={0,200,300,500,700,1000}, sample for=const, }, }, colorbar horizontal, colormap access=const, colorbar style={xtick=data,font=\tiny, /pgf/number format/precision=0}, colormap access=const, ]

Please refer to the documentation of sample for.

The default width of this interval is the mesh width of the color map (the value h), i.e. it will always be as large as the other intervals. If the color map has nonuniform distances, the smallest encountered mesh width is used for the extra interval. This can be seen if we omit the key and add some artificial color at the right end manually – we only need to ensure that the rightmost interval has the correct length. In our example above, the smallest mesh width is \(100\), so we can generate an equivalent result by means of

(-tikz- diagram)

\pgfplotscolorbardrawstandalone[ colormap={nonuniform}{ of colormap={ viridis, target pos={0,200,300,500,700,1000} }, color(1100)=(red) }, colorbar horizontal, colormap access=const, colorbar style={xtick=data,font=\tiny, /pgf/number format/precision=0}, colormap access=const, ]

As already mentioned, colormap access=const ignores the rightmost color (“red”). Note that this approach is almost the same as the internal implementation of sample for=const.

The value of colormap access/extra interval width=(math image)fraction(math image) can also be used to customize the width of the artificial interval: it is a fraction of the total width and accepted values are \(0\le \)(math image)fraction(math image)\(\le 0.9\) where \(0\) disables the extra interval and \(0.9\) corresponds to \(90\%\) of the resulting width. Any non-\(0\) value for (math image)fraction(math image) creates an extra interval and its width is (math image)fraction(math image) percent of the entire color map. The special magic value colormap access/extra interval width=h will use the colormap’s mesh width. If the colormap has nonuniform distances, it will use the smallest encountered mesh width. This is the default.

Note that (math image)fraction(math image) is a property of the colormap. The key defines it for the current color map only. Defining a new colormap uses the default width for the new colormap (but keeps the configured value for the old colormap).

Attention:

at the time of this writing, uniform color maps only support the default interval width ‘h’ and (math image)fraction(math image)\(=0\), further customization is only possible for nonuniform color maps. If you ever need to work around this limitation, you should file a feature requests and move one of your color position until the colormap becomes a nonuniform colormap.

4.7.6.5Choosing a Colormap Entry as Normal Color
  • /pgfplots/color of colormap=(math image)value(math image)

  • /pgfplots/color of colormap=(math image)value(math image) of (math image)colormap name(math image)

  • [See also Section 4.7.6.4 on page (page for section 4.7.6.4) for how to employ this within colormap definitions]

    Defines the TikZ color to be the (math image)value(math image) of (math image)colormap name(math image). If (math image)colormap name(math image) is omitted, the value of colormap name is evaluated (i.e. the current colormap is used).

    The argument (math image)value(math image) is expected to be a number in the range \([0,1000]\) where \(0\) resembles the lower end of the color map and \(1000\) the upper end.

    Current colormap (hot):

    (-tikz- diagram)

    \tikz\fill [color of colormap={800}, thick, draw=.!60!black] (0,0) -- (1,1) -- (2,1) circle (10pt);

    The key computes the requested color and calls color=.. Keep in mind that the magic color name ‘.’ always reflects the “current color”, i.e. the result of color=(math image)some color(math image). Also keep in mind that color is a TikZ command which merely defines the color, you also have to provide one of ‘draw’ or ‘fill’ such that it has an effect. Since ‘.’ is a normal color, we can write draw=.!60!black to combine it with another color.

    viridis:

    (-tikz- diagram)

    \pgfplotsset{colormap name=viridis} \tikz\fill [color of colormap={1000},thick, draw=.!60!black] (0,0) -- (1,1) -- (2,1) circle (10pt);

    (-tikz- diagram)

    \tikz\fill [color of colormap={300 of viridis},thick, draw=.!60!black] (0,0) -- (1,1) -- (2,1) circle (10pt);

    The argument (math image)colormap name(math image) is either a valid argument of colormap name or a style name like colormap/cool:

    cool:

    (-tikz- diagram)

    \tikz\fill [color of colormap={300 of colormap/cool}, thick,draw=.!60!black] (0,0) -- (1,1) -- (2,1) circle (10pt);

    This last syntax allows to evaluate colormaps lazily. However, if you have many references to the same colormap, it makes sense to write \pgfplotsset{colormap/cool} first followed by many references to color of colormap={... of cool} in order to avoid unnecessary lazy evaluations.

    It is possible to write lots of invocations without an explicit (math image)colormap name(math image), i.e. lots of invocations of sorts color of colormap=(math image)value(math image). They will all use the colormap name which is active at that time.

    Note that there are actually keys with two key prefixes: /pgfplots/color of colormap and an alias /tikz/color of colormap. This allows to use the keys both for plain TikZ graphics and for pgfplots.

    See also colormap access=map.

  • /pgfplots/index of colormap=(math image)index(math image)

  • /pgfplots/index of colormap=(math image)index(math image) of (math image)colormap name(math image)

  • [See also Section 4.7.6.4 on page (page for section 4.7.6.4) for how to employ this within colormap definitions]

    A variant of color of colormap which accesses the (math image)colormap name(math image) by index. Consequently, the argument (math image)index(math image) is an integer number in the range \(0,\dotsc ,N-1\) where \(N\) is the number of colors which define the (math image)colormap name(math image). A (math image)index(math image) outside of this range is automatically clipped to the upper bound.

    (-tikz- diagram) (-tikz- diagram) (-tikz- diagram) (-tikz- diagram) (-tikz- diagram) (-tikz- diagram)

    \pgfplotsset{colormap/jet} \foreach \i in { 0,...,\pgfplotscolormaplastindexof{jet} }{ \tikz\fill [ index of colormap={\i of jet}, thick, draw=.!60!black, ] (0,0) rectangle (10pt,6pt); }
    • \pgfplotscolormapsizeof{(math image)colormap name(math image)}

    • Expands to the number of colors which make up (math image)colormap name(math image).

      If the argument (math image)colormap name(math image) is an unknown colormap, it expands to \(0\).

    • \pgfplotscolormaplastindexof{(math image)colormap name(math image)}

    • Expands to the last index of (math image)colormap name(math image), i.e. it is a convenience method to access \(N-1\).

      If the argument (math image)colormap name(math image) is an unknown colormap, it expands to \(-1\).

    See also colormap access=direct.

  • /pgfplots/const color of colormap=(math image)value(math image)

  • /pgfplots/const color of colormap=(math image)value(math image) of (math image)colormap name(math image)

  • [See also Section 4.7.6.4 on page (page for section 4.7.6.4) for how to employ this within colormap definitions]

    Defines the TikZ color to be the (math image)value(math image) of (math image)colormap name(math image). If (math image)colormap name(math image) is omitted, the value of colormap name is evaluated (i.e. the current colormap is used).

    This key is almost the same as color of colormap, except that it uses colormap access=piecewise constant in order to determine the interpolated value.

4.7.7Cycle Lists – Options Controlling Line Styles
  • /pgfplots/cycle list={(math image)list(math image)}

  • /pgfplots/cycle list name={(math image)name(math image)}

  • Allows to specify a list of plot specifications which will be used for each \addplot command without explicit plot specification. Thus, the currently active cycle list will be used if you write either \addplot+[(math image)keys(math image)] ...; or if you don’t use square brackets as in \addplot[(math image)explicit plot specification(math image)] ...;.

    The list element with index \(i\) will be chosen where \(i\) is the index of the current \addplot command (see also the cycle list shift key which allows to use \(i+n\) instead). This indexing does also include plot commands which don’t use the cycle list.

    There are several possibilities to change the currently active cycle list:

4.7.7.1Predefined Lists

Use one of the predefined lists,40

The definitions of all predefined cycle lists follow (see the end of this paragraph for a syntax description).

\pgfplotscreateplotcyclelist{color}{ blue,every mark/.append style={fill=blue!80!black},mark=*\\ red,every mark/.append style={fill=red!80!black},mark=square*\\ brown!60!black,every mark/.append style={fill=brown!80!black},mark=otimes*\\ black,mark=star\\ blue,every mark/.append style={fill=blue!80!black},mark=diamond*\\ red,densely dashed,every mark/.append style={solid,fill=red!80!black},mark=*\\ brown!60!black,densely dashed,every mark/.append style={ solid,fill=brown!80!black},mark=square*\\ black,densely dashed,every mark/.append style={solid,fill=gray},mark=otimes*\\ blue,densely dashed,mark=star,every mark/.append style=solid\\ red,densely dashed,every mark/.append style={solid,fill=red!80!black},mark=diamond*\\ }
\pgfplotscreateplotcyclelist{black white}{ every mark/.append style={fill=gray},mark=*\\ every mark/.append style={fill=gray},mark=square*\\ every mark/.append style={fill=gray},mark=otimes*\\ mark=star\\ every mark/.append style={fill=gray},mark=diamond*\\ densely dashed,every mark/.append style={solid,fill=gray},mark=*\\ densely dashed,every mark/.append style={solid,fill=gray},mark=square*\\ densely dashed,every mark/.append style={solid,fill=gray},mark=otimes*\\ densely dashed,every mark/.append style={solid},mark=star\\ densely dashed,every mark/.append style={solid,fill=gray},mark=diamond*\\ }
\pgfplotscreateplotcyclelist{exotic}{ teal,every mark/.append style={fill=teal!80!black},mark=*\\ orange,every mark/.append style={fill=orange!80!black},mark=square*\\ cyan!60!black,every mark/.append style={fill=cyan!80!black},mark=otimes*\\ red!70!white,mark=star\\ lime!80!black,every mark/.append style={fill=lime},mark=diamond*\\ red,densely dashed,every mark/.append style={solid,fill=red!80!black},mark=*\\ yellow!60!black,densely dashed, every mark/.append style={solid,fill=yellow!80!black},mark=square*\\ black,every mark/.append style={solid,fill=gray},mark=otimes*\\ blue,densely dashed,mark=star,every mark/.append style=solid\\ red,densely dashed,every mark/.append style={solid,fill=red!80!black},mark=diamond*\\ }
% note that "." is the currently defined Tikz color. \pgfplotscreateplotcyclelist{mark list}{ every mark/.append style={solid,fill=\pgfplotsmarklistfill},mark=*\\ every mark/.append style={solid,fill=\pgfplotsmarklistfill},mark=square*\\ every mark/.append style={solid,fill=\pgfplotsmarklistfill},mark=triangle*\\ every mark/.append style={solid},mark=star\\ every mark/.append style={solid,fill=\pgfplotsmarklistfill},mark=diamond*\\ every mark/.append style={solid,fill=\pgfplotsmarklistfill!40},mark=otimes*\\ every mark/.append style={solid},mark=|\\ every mark/.append style={solid,fill=\pgfplotsmarklistfill},mark=pentagon*\\ every mark/.append style={solid},mark=text,text mark=p\\ every mark/.append style={solid},mark=text,text mark=a\\ }

In this context, a common fill color expression can be customized using mark list fill:

  • /pgfplots/mark list fill={(math image)color(math image)} (initially .!80!black)

  • Allows to customize the fill color for the mark list and mark list*.

    For example, if you have black as color, the alternative choice mark list fill=.!50!white will produce much better results.

% note that "." is the currently defined Tikz color. \pgfplotscreateplotcyclelist{mark list*}{ every mark/.append style={solid,fill=\pgfplotsmarklistfill},mark=*\\ every mark/.append style={solid,fill=\pgfplotsmarklistfill},mark=square*\\ every mark/.append style={solid,fill=\pgfplotsmarklistfill},mark=triangle*\\ every mark/.append style={solid,fill=\pgfplotsmarklistfill},mark=halfsquare*\\ every mark/.append style={solid,fill=\pgfplotsmarklistfill},mark=pentagon*\\ every mark/.append style={solid,fill=\pgfplotsmarklistfill},mark=halfcircle*\\ every mark/.append style={solid,fill=\pgfplotsmarklistfill,rotate=180},mark=halfdiamond*\\ every mark/.append style={solid,fill=\pgfplotsmarklistfill!40},mark=otimes*\\ every mark/.append style={solid,fill=\pgfplotsmarklistfill},mark=diamond*\\ every mark/.append style={solid,fill=\pgfplotsmarklistfill},mark=halfsquare right*\\ every mark/.append style={solid,fill=\pgfplotsmarklistfill},mark=halfsquare left*\\ }

40 In an early version, these lists were called \coloredplotspeclist and \blackwhiteplotspeclist which appeared to be unnecessarily long, so they have been renamed. The old names are still accepted, however.

4.7.7.2Defining Own Cycle Lists

The second choice for cycle lists is to provide each entry directly as argument to cycle list,

(-tikz- diagram)

% Preamble: \pgfplotsset{width=7cm,compat=1.18} \begin{tikzpicture} \begin{loglogaxis}[ cycle list={ {blue,mark=*}, {red,mark=square}, {dashed,mark=o}, {loosely dotted,mark=+}, {brown!60!black,mark=otimes*, mark options={fill=brown!40}, }% <-- don't add a comma here }, ] \plotcoords \legend{$d=2$,$d=3$,$d=4$,$d=5$,$d=6$} \end{loglogaxis} \end{tikzpicture}

(This example list requires \usetikzlibrary{plotmarks}).

The input format is described below in more detail.

4.7.7.3Defining and Labeling Own Cycle Lists

The last method for cycle lists is to combine the define named cycle lists in the preamble and use them with ‘cycle list name’:

  • \pgfplotscreateplotcyclelist{(math image)name(math image)}{(math image)list(math image)}

\pgfplotscreateplotcyclelist{mylist}{ {blue,mark=*}, {red,mark=square}, {dashed,mark=o}, {loosely dotted,mark=+}, {brown!60!black,mark options={fill=brown!40},mark=otimes*}% <-- don't add a comma here } ... \begin{axis}[cycle list name=mylist] ... \end{axis}
4.7.7.4Defining Cycle Lists: Input Format

A cycle list is defined by key–value pairs of sorts cycle list={(math image)list(math image)} or by the equivalent macro outlined above, \pgfplotscreateplotcyclelist{(math image)name(math image)}{(math image)list(math image)}.

In this context, the argument (math image)list(math image) is usually a comma separated list of lists of style keys like colors, line styles, marker types and marker styles. This “comma list of comma lists” structure requires to encapsulate the inner list using curly braces:

\pgfplotscreateplotcyclelist{mylist}{ {blue,mark=*}, {red,mark=square}, {dashed,mark=o}, {loosely dotted,mark=+}, {brown!60!black,mark options={fill=brown!40},mark=otimes*}% <-- don't add a comma here }

Alternatively, one can terminate the inner lists (i.e. those for one single plot) with ‘\\’:

\begin{axis}[ cycle list={ blue,mark=*\\ red,mark=square\\ dashed,mark=o\\ loosely dotted,mark=+\\ brown!60!black,mark options={fill=brown!40},mark=otimes*\\ }, ] ... \end{axis}

In this case, the last entry also needs a terminating ‘\\’, but one can omit braces around the single entries.

4.7.7.5Manipulating Associations of Cycle Lists to Plots

Special case:

If the result is negative, \(i+n <0\), the list index \(-(i+n)\) will be taken. For example, cycle list shift=-10 and \(i<10\) will result in list index \(10-i\). Note that you can use reverse legend to reverse legends, so this feature is probably never needed.

4.7.7.6Defining Cycle Lists based on Color Maps

In addition to defining cycle lists from scratch, pgfplots supports dedicated input definitions of cycle list=(math image)list(math image) which allow to acquire values from an existing colormap. In this case, (math image)list(math image) contains keys enclosed in square brackets:

The first syntax, of colormap, allows to convert the colors of a colormap to a cycle list. It can be specified without argument by means of cycle list={[of colormap]} in order to take the value of the most recently assigned colormap name (i.e. the current colormap). It can also be specified as cycle list={[of colormap=name]} in which case it will use the specified colormap name=name. In both cases, the definition merely converts the colors as they are found in the colormap into the cycle list, i.e. there is no interpolation involved. Applying this to the default colormap name=hot which has \(4\) colors results in the following example:

(-tikz- diagram)

% Preamble: \pgfplotsset{width=7cm,compat=1.18} \begin{tikzpicture} \begin{axis}[ colormap name=hot,colorbar, cycle list={[of colormap]}, % cycle from colormap manual style, ] \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \end{axis} \end{tikzpicture}

Note that since hot has \(4\) colors, the cycle list also contains \(4\) entries which are repeated every \(4\) plots.

The second possibility resembles samples of colormap: it expects samples of colormap={(math image)number(math image)} of (math image)colormap name(math image). It chooses (math image)number(math image) samples of the selected colormap.

The third possibility is similar to color of colormap: it expects colors of colormap={(math image)list(math image)} or colors of colormap={(math image)list(math image)} of (math image)colormap name(math image). This choice interpolates colors and expects a (math image)list(math image) of values in the range \([0,1000]\) where \(0\) is the lowest element in the colormap and \(1000\) is its highest element:

(-tikz- diagram)

% Preamble: \pgfplotsset{width=7cm,compat=1.18} \begin{tikzpicture} \begin{axis}[ colormap name=hot,colorbar, cycle list={ [colors of colormap={0,100,...,1000}]}, % cycle from colormap manual style, ] \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \end{axis} \end{tikzpicture}

In this case, we specified \(11\) colors and have \(11\) plots. Clearly, interpolated colors are of limited use and are only applicable for special use cases. Use only cycle lists of this sort if the colormap allows a suitable distinction of adjacent plot lines! Note that colors of colormap is quite similar to the related way to build colormaps based on existing colormaps as outlined in Section 4.7.6.4 on page (page for section 4.7.6.4).

A related choice is indices of colormap={(math image)list(math image)}. As above, it accepts an optional ‘of’ clause of the form indices of colormap={(math image)list(math image)} of (math image)colormap name(math image). The main argument is a list of indices \(0\le N_i < N\) where \(N\) is the number colors in the colormap definition (compare the documentation of index of colormap). Indices which are out of range are clipped to the nearest index. For example, viridis comes with \(\pgfplotscolormapsizeof {viridis}\) elements and we can write

(-tikz- diagram)

% Preamble: \pgfplotsset{width=7cm,compat=1.18} \begin{tikzpicture} \begin{axis}[ colormap name=viridis,colorbar, cycle list={ [indices of colormap={0,4,8,12,17} of viridis]}, % cycle from colormap manual style, ] \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \end{axis} \end{tikzpicture}

Note that ‘ of viridis’ is actually redundant as viridis was already selected in this case.

The complete syntax on how to customize of colormap is the same as the building blocks to define colormaps based on other colormaps as described in Section 4.7.6.4 on page (page for section 4.7.6.4) – with the difference that cycle list={[of colormap]} inserts the selected colors into the cycle list instead of a colormap.

Note that all these special lists are valid arguments for \pgfplotscreateplotcyclelist and can also appear as sublists in cycle multi list and its variants.

Since creating a cycle list from a colormap necessarily results in plots without markers and line style variations, it makes sense to combine the result with cycle multiindex* list, i.e. to join two existing lists. The following example joins a pure color list with markers:

(-tikz- diagram)

% Preamble: \pgfplotsset{width=7cm,compat=1.18} \begin{tikzpicture} \begin{axis}[ colormap name=hot,colorbar, cycle multiindex* list={ [samples of colormap=11]\nextlist mark list\nextlist }, cycle from colormap manual style, ] \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \end{axis} \end{tikzpicture}

Please refer to the next subsection for details about cycle multiindex* list.

Note that the preceding examples all use the following style.

Remark:

It is possible to call \pgfplotsset{cycle list={(math image)a list(math image)}} or cycle list name between plots. Such a setting remains effective until the end of the current group (that means curly braces). Every \addplot command queries the cycle list using the plot index; it doesn’t hurt if cycle lists have changed in the meantime.

4.7.7.7Building Block to Combine Different Cycle Lists

The following keys allow to combined different cycle lists in order to build more complex ones.

Using Sublists

The (math image)list \(i\)(math image) entry can also contain just the first \(n\) elements of an already known cycle list name using the syntax [(math image)number(math image) of](math image)cycle list name(math image). For example [2 of]mark list will use the first \(2\) elements of mark list:

(-tikz- diagram)

% Preamble: \pgfplotsset{width=7cm,compat=1.18} \begin{tikzpicture} \begin{axis}[ title={Cycle 2 marks between successive plots, then colors}, cycle multi list={ color list\nextlist [2 of]mark list }, samples=3, legend entries={0,...,20}, legend pos=outer north east, ] \addplot {x}; \addplot {x-1}; \addplot {x-2}; \addplot {x-3}; \addplot {x-4}; \addplot {x-5}; \addplot {x-6}; \addplot {x-7}; \addplot {x-8}; \addplot {x-9}; \addplot {x-10}; \addplot {x-11}; \end{axis} \end{tikzpicture}

41 For those who prefer formulas: The plot with index \(0 \le i < N\) will use cycle list offsets \(i_0,i_1,\dotsc ,i_k\), \(0 \le i_m < N_m\) where \(k\) is the number of arguments provided to cycle multi list and \(N_m\) is the number of elements in the \(m\)th cycle list. The offsets \(i_m\) are computed in a loop { int tmp=i; for( int m=k-1; m>=0; m=m-1 ) { i_m = tmp%N_m; tmp = tmp/N_m; }}.

4.7.8Axis Background