Why Does a PGFPlots Cycle List Produce No Colors?
At a glance
- 1. Define plot styles
Put each color and other plot settings in its own braced cycle-list entry.
- 2. Select the list
Use cycle list name for a named list, or cycle list for entries written directly in the axis options.
- 3. Add plot options safely
Use \addplot+ when you want extra settings while keeping the selected cycle style.
- 4. Check for overrides
Look for explicit color or draw settings that may force the plots to appear black.
A PGFPlots cycle list assigns styles to successive \addplot commands. If your curves all look black, the list may not be selected, its entries may be malformed, or another plot option may be overriding the colors. This guide shows a working setup and a practical way to diagnose the problem.
What a cycle list controls
Each entry in a cycle list is a style for one plot. For example, the first plot can be blue, the second red, and the third green. After PGFPlots uses the last entry, it cycles back through the list. A cycle list does not assign a different color to every data point in one plot; for that, you need a different technique, such as a colormap.
For a custom list, each entry should be enclosed in braces. You can define a named list with \pgfplotscreateplotcyclelist and select it in an axis using cycle list name. Alternatively, write the styles directly in the axis option cycle list.
A working named cycle list
This complete example defines three styles and applies them to three curves. It uses the pgfplots package; the compat setting asks PGFPlots to use a known version of its behavior.
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\pgfplotscreateplotcyclelist{my colors}{%
{blue,solid,mark=*},
{red,dashed,mark=square*},
{green!50!black,dotted,mark=triangle*},
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
cycle list name=my colors,
xlabel={$x$},
ylabel={$y$},
legend entries={$x$, $x^2$, $\sqrt{x}$},
]
\addplot+[domain=0:2,samples=60] {x};
\addplot+[domain=0:2,samples=60] {x^2};
\addplot+[domain=0:2,samples=60] {sqrt(x)};
\end{axis}
\end{tikzpicture}
\end{document}
The first plot uses the first list entry, the second uses the next, and the third uses the last. The + in \addplot+ lets you add settings such as domain and samples while retaining the cycle-list style. You can also write the list inline instead of defining it by name:
\begin{axis}[
cycle list={
{blue,solid},
{red,dashed},
{green!50!black,dotted},
},
]
Use either cycle list name=my colors for a named list or cycle list={...} for an inline list. They serve different purposes: the first selects a list already defined by name; the second provides the entries directly.
Diagnose plots that appear black
Check these points in order:
- Is the custom list selected? Defining a list with
\pgfplotscreateplotcyclelistdoes not select it by itself. Addcycle list name=<name>to the relevantaxisoptions, using the exact name from the definition. - Are the entries grouped? Write each style as its own braced entry, for example
{blue,mark=*}. This makes the intended plot-by-plot sequence clear and avoids treating the styles as one entry. - Does each curve use a separate
\addplot? The list advances per plot command, not per coordinate. If several curves are combined into one plot, they will not receive separate cycle entries. - Are plot options interfering? Use
\addplot+[...]when you want to add options while keeping the cycle-list style. An explicit setting such ascolor=blackordraw=blackcan still force a plot to draw in black, so remove or change conflicting settings. - Is a monochrome style active? Look for axis or document settings that select a black-and-white cycle list or set plot colors globally. For diagnosis, try the small example above in a fresh document.
Common mistakes
A frequent mistake is to create a named list but put its name in the wrong key. cycle list name=my colors selects a named list; cycle list={...} defines an inline list. Another is to include a style like black unintentionally, or to set draw=black after the cycle style has been applied.
Also check that you are inspecting the plot lines, not just the markers. If you use custom marker settings, marker fill and outline can be controlled separately. A filled marker might therefore have a different appearance from its line. For the simplest test, use entries such as {blue,thick} and {red,thick} with ordinary line plots.
If your goal is to color values within one surface, scatter plot, or bar plot according to their magnitude, a cycle list is not the right tool: it chooses a style per plot. Use a colormap or a plot-specific point/bar coloring option instead.
References
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.