Colors and Styles in PGFPlots
Customize the visual appearance of your plots with colors, styles, and colormaps.
Basic Colors
\begin{axis}
% Named colors
\addplot[red] {x};
\addplot[blue] {x + 1};
\addplot[green] {x + 2};
\addplot[orange] {x + 3};
\addplot[purple] {x + 4};
% Color mixing
\addplot[red!50!blue] {x + 5}; % 50% red, 50% blue
\addplot[green!30!black] {x + 6}; % Darker green
\addplot[blue!20] {x + 7}; % Light blue (20% opacity)
\end{axis}Custom Colors
% Define custom colors in preamble
\definecolor{myblue}{RGB}{30, 100, 200}
\definecolor{myred}{HTML}{E74C3C}
\definecolor{mygray}{gray}{0.5}
\begin{axis}
\addplot[color=myblue, thick] {x};
\addplot[color=myred, thick] {x^2};
\addplot[color=mygray, thick] {sqrt(x)};
\end{axis}Line Styles
\begin{axis}
% Line patterns
\addplot[solid] {x}; % Default
\addplot[dashed] {x + 1};
\addplot[dotted] {x + 2};
\addplot[dashdotted] {x + 3};
\addplot[dashdotdotted] {x + 4};
% Line width
\addplot[thin] {x + 5};
\addplot[thick] {x + 6};
\addplot[very thick] {x + 7};
\addplot[ultra thick] {x + 8};
\addplot[line width=2pt] {x + 9};
% Combined
\addplot[blue, thick, dashed] {x + 10};
\end{axis}Markers
\begin{axis}
% Marker types
\addplot[mark=*] coordinates {(0,0) (1,1) (2,2)};
\addplot[mark=o] coordinates {(0,1) (1,2) (2,3)};
\addplot[mark=square*] coordinates {(0,2) (1,3) (2,4)};
\addplot[mark=square] coordinates {(0,3) (1,4) (2,5)};
\addplot[mark=triangle*] coordinates {(0,4) (1,5) (2,6)};
\addplot[mark=diamond*] coordinates {(0,5) (1,6) (2,7)};
\addplot[mark=+] coordinates {(0,6) (1,7) (2,8)};
\addplot[mark=x] coordinates {(0,7) (1,8) (2,9)};
% Marker options
\addplot[
mark=*,
mark size=3pt,
mark options={fill=red, draw=blue}
] coordinates {(0,8) (1,9) (2,10)};
\end{axis}Cycle Lists
Define automatic color/style cycling for multiple plots:
% Define custom cycle list
\pgfplotscreateplotcyclelist{my list}{
{blue, mark=*},
{red, mark=square*},
{green!60!black, mark=triangle*},
{orange, mark=diamond*}
}
\begin{axis}[
cycle list name=my list
]
\addplot {x}; % Uses blue, mark=*
\addplot {x^2}; % Uses red, mark=square*
\addplot {x^3}; % Uses green, mark=triangle*
\addplot {sqrt(x)}; % Uses orange, mark=diamond*
\end{axis}Predefined Cycle Lists
\begin{axis}[
% Predefined cycle lists:
cycle list name=color list, % Just colors
% cycle list name=mark list, % Just markers
% cycle list name=exotic, % Exotic color combinations
% cycle list name=black white, % Grayscale with patterns
]Colormaps
% For 3D and scatter plots
\begin{axis}[
colormap/viridis, % Modern perceptually uniform
% Other options:
% colormap/hot
% colormap/cool
% colormap/jet
% colormap/bluered
% colormap/greenyellow
% colormap/blackwhite
colorbar % Show colorbar
]
\addplot3[surf] {x*y};
\end{axis}
% Custom colormap
\pgfplotsset{
colormap={my colormap}{
rgb255(0cm)=(0,0,255);
rgb255(1cm)=(255,255,255);
rgb255(2cm)=(255,0,0)
}
}Fill Styles
\begin{axis}
% Solid fill
\addplot[fill=blue!30] {x^2} \closedcycle;
% Fill with opacity
\addplot[fill=red, fill opacity=0.3] {x^2 + 2} \closedcycle;
% Pattern fill (requires patterns library)
% \addplot[pattern=north east lines] {x^2 + 4} \closedcycle;
\end{axis}Global Style Settings
\pgfplotsset{
% Apply to all plots
every axis plot/.append style={
thick,
mark size=2pt
},
% Define reusable style
my plot style/.style={
blue,
thick,
mark=*,
mark options={fill=white}
}
}
\begin{axis}
\addplot[my plot style] {x};
\addplot[my plot style, red] {x^2};
\end{axis}Next Steps
Continue learning PGFPlots:
- Multiple Plots - Subplots and grouping
- Legends - Legend customization
- 3D Plots - Apply colormaps to 3D
Colors and Styles in PGFPlots
Customize the visual appearance of your plots with colors, styles, and colormaps.
Basic Colors
\begin{axis}
% Named colors
\addplot[red] {x};
\addplot[blue] {x + 1};
\addplot[green] {x + 2};
\addplot[orange] {x + 3};
\addplot[purple] {x + 4};
% Color mixing
\addplot[red!50!blue] {x + 5}; % 50% red, 50% blue
\addplot[green!30!black] {x + 6}; % Darker green
\addplot[blue!20] {x + 7}; % Light blue (20% opacity)
\end{axis}Custom Colors
% Define custom colors in preamble
\definecolor{myblue}{RGB}{30, 100, 200}
\definecolor{myred}{HTML}{E74C3C}
\definecolor{mygray}{gray}{0.5}
\begin{axis}
\addplot[color=myblue, thick] {x};
\addplot[color=myred, thick] {x^2};
\addplot[color=mygray, thick] {sqrt(x)};
\end{axis}Line Styles
\begin{axis}
% Line patterns
\addplot[solid] {x}; % Default
\addplot[dashed] {x + 1};
\addplot[dotted] {x + 2};
\addplot[dashdotted] {x + 3};
\addplot[dashdotdotted] {x + 4};
% Line width
\addplot[thin] {x + 5};
\addplot[thick] {x + 6};
\addplot[very thick] {x + 7};
\addplot[ultra thick] {x + 8};
\addplot[line width=2pt] {x + 9};
% Combined
\addplot[blue, thick, dashed] {x + 10};
\end{axis}Markers
\begin{axis}
% Marker types
\addplot[mark=*] coordinates {(0,0) (1,1) (2,2)};
\addplot[mark=o] coordinates {(0,1) (1,2) (2,3)};
\addplot[mark=square*] coordinates {(0,2) (1,3) (2,4)};
\addplot[mark=square] coordinates {(0,3) (1,4) (2,5)};
\addplot[mark=triangle*] coordinates {(0,4) (1,5) (2,6)};
\addplot[mark=diamond*] coordinates {(0,5) (1,6) (2,7)};
\addplot[mark=+] coordinates {(0,6) (1,7) (2,8)};
\addplot[mark=x] coordinates {(0,7) (1,8) (2,9)};
% Marker options
\addplot[
mark=*,
mark size=3pt,
mark options={fill=red, draw=blue}
] coordinates {(0,8) (1,9) (2,10)};
\end{axis}Cycle Lists
Define automatic color/style cycling for multiple plots:
% Define custom cycle list
\pgfplotscreateplotcyclelist{my list}{
{blue, mark=*},
{red, mark=square*},
{green!60!black, mark=triangle*},
{orange, mark=diamond*}
}
\begin{axis}[
cycle list name=my list
]
\addplot {x}; % Uses blue, mark=*
\addplot {x^2}; % Uses red, mark=square*
\addplot {x^3}; % Uses green, mark=triangle*
\addplot {sqrt(x)}; % Uses orange, mark=diamond*
\end{axis}Predefined Cycle Lists
\begin{axis}[
% Predefined cycle lists:
cycle list name=color list, % Just colors
% cycle list name=mark list, % Just markers
% cycle list name=exotic, % Exotic color combinations
% cycle list name=black white, % Grayscale with patterns
]Colormaps
% For 3D and scatter plots
\begin{axis}[
colormap/viridis, % Modern perceptually uniform
% Other options:
% colormap/hot
% colormap/cool
% colormap/jet
% colormap/bluered
% colormap/greenyellow
% colormap/blackwhite
colorbar % Show colorbar
]
\addplot3[surf] {x*y};
\end{axis}
% Custom colormap
\pgfplotsset{
colormap={my colormap}{
rgb255(0cm)=(0,0,255);
rgb255(1cm)=(255,255,255);
rgb255(2cm)=(255,0,0)
}
}Fill Styles
\begin{axis}
% Solid fill
\addplot[fill=blue!30] {x^2} \closedcycle;
% Fill with opacity
\addplot[fill=red, fill opacity=0.3] {x^2 + 2} \closedcycle;
% Pattern fill (requires patterns library)
% \addplot[pattern=north east lines] {x^2 + 4} \closedcycle;
\end{axis}Global Style Settings
\pgfplotsset{
% Apply to all plots
every axis plot/.append style={
thick,
mark size=2pt
},
% Define reusable style
my plot style/.style={
blue,
thick,
mark=*,
mark options={fill=white}
}
}
\begin{axis}
\addplot[my plot style] {x};
\addplot[my plot style, red] {x^2};
\end{axis}Next Steps
Continue learning PGFPlots:
- Multiple Plots - Subplots and grouping
- Legends - Legend customization
- 3D Plots - Apply colormaps to 3D