Tx · LaTeX & TikZ

How to Set Line Colors in PGFPlots

Updated 13 October 2026

At a glance

  1. 1. Choose the scope

    Set a color on one plot for a one-off change, or use a cycle list to style several series consistently.

  2. 2. Set one plot color

    Add a drawing-color option to the plot, such as draw=red, and include any desired line width or marker options.

  3. 3. Define a cycle list

    Create a list of color and style combinations, then select it in the axis options.

  4. 4. Plot the series

    Each plot uses the next cycle-list entry; the sequence starts over after its final entry.

To change a PGFPlots line color, set the drawing color on that plot. If you have several series, a cycle list is usually easier: it assigns a color and optional line style to each plot in sequence. The examples below show both methods, along with a complete document you can compile.

Set the color of one line

Add a color option to \addplot. For example, \addplot[draw=red, thick] {x}; draws a thick red line. You can also use the shorthand red in place of draw=red; the explicit draw= form makes clear that you are setting the line color.

Common color names such as red, blue, and black are available through the color support loaded by PGFPlots. To define your own color, load xcolor and use its \definecolor command. For example, \definecolor{myblue}{HTML}{1F77B4} defines a color you can use as draw=myblue.

Options can be combined. For example:

\addplot[draw=blue, thick, dashed, mark=*] {x};

This sets a blue dashed line, makes it thicker than the default, and places a marker at each plotted sample. If you only want to change the line color, you do not need to specify the other options.

Assign colors to multiple lines with a cycle list

A cycle list tells PGFPlots which styles to use for successive plots in an axis. Define a named list in the preamble, then select it with cycle list name in the axis options:

\pgfplotscreateplotcyclelist{mycolors}{
  {blue,thick},
  {red,thick},
  {green,thick}
}

Then, in the axis, write cycle list name=mycolors. The first plot uses the first entry, the second plot uses the second, and so on. Once PGFPlots reaches the end of the list, it starts again. Each entry can include more than a color: line width, dash pattern, and marker options can all be part of the style.

Cycle lists are useful when you want a predictable palette across figures. They also make it easier to distinguish lines in black-and-white print by varying markers or line styles as well as colors.

Complete working example

This document shows explicit colors in the first axis and a custom cycle list in the second. It requires the pgfplots package and compiles as a standard LaTeX document.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\pgfplotscreateplotcyclelist{mycolors}{
  {blue,thick},
  {red,thick},
  {green,thick}
}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
  width=10cm,
  height=6cm,
  title={Explicit line colors},
  domain=0:4,
  samples=50,
  legend pos=north west
]
  \addplot[draw=red,thick] {x};
  \addlegendentry{$y=x$}
  \addplot[draw=blue,thick] {4-x};
  \addlegendentry{$y=4-x$}
\end{axis}
\end{tikzpicture}

\bigskip

\begin{tikzpicture}
\begin{axis}[
  width=10cm,
  height=6cm,
  title={A custom cycle list},
  domain=0:4,
  samples=50,
  cycle list name=mycolors,
  legend pos=north west
]
  \addplot {x};
  \addlegendentry{$y=x$}
  \addplot {4-x};
  \addlegendentry{$y=4-x$}
  \addplot {0.5*x+1};
  \addlegendentry{$y=0.5x+1$}
\end{axis}
\end{tikzpicture}

\end{document}

The cycle list is selected separately for each axis. If you want the same colors in multiple axes, set the same cycle list name on each one.

Common mistakes

  • Changing the fill instead of the line: fill=red colors a filled region or marker interior; use draw=red for the line itself.
  • Expecting a custom list to affect every axis: Put cycle list name=mycolors in the options of each axis that should use it.
  • Using a colormap for ordinary line series: A colormap is mainly for mapping numeric values to colors, such as values in a surface or scatter plot. For a sequence of ordinary line plots, use a cycle list.
  • Assuming colors never repeat: A cycle list is reused when its entries run out. Add more entries or vary markers and line styles if you need more series to remain distinct.

References

  1. PGFPlots Manual

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.