I am looping over several files and plotting the content on an axis in pgfplots. I would like to plot each entry as a different color (a shade of blue, for example). While the plotting works fine, I'm having a lot of trouble being able to change the color in each 'for' loop. There are similar questions here, but I can't get any to work quite right.
here is a simple example…
\documentclass{article}
\usepackage{color}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\pgfplotsset{width=7cm,compat=1.3}
\usepackage{tikz}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{loglogaxis}
\foreach \n in {1,...,20} {
\addplot[
color=blue,
] table {data/datafile_\n.dat};
}
\end{loglogaxis}
\end{tikzpicture}
\end{figure}
\end{document}
I would like to have something like
color=blue!\n!white
but that doesn't seem to have any effect on the plot. More specifically, I would like to perform some operation on the counter \n
to have more control of the color. Fumbling around at similar questions and the pgfplots manual, I have tried replacing the \foreach
loop with
\pgfplotsinvokeforeach{1,...,20}{
This lets me do something like color=blue!#1!white
, but if I want to operate on the counter itself with something like
\pgfmathtruncatemacro{\k}{#1*5}
and then use color=blue!\k!white
, I don't get the desired result – the color stays constant.
Extremely new to pgfplots and tikz, so any help would be much appreciated!
Best Answer
Do you mean this?