TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I use pi the number in a \foreach in pgfplots?

\documentclass[tikz, dvipsnames]{standalone}
\pgfplotsset{compat = 1.8}
    \foreach \v/\colo in {0/red, {pi/4}/blue, {pi/2}/orange, {3*pi/4}/green,
      {5*pi/4}/Purple, {3*pi/2}/Salmon, {7pi/4}/SeaGreen}{
      \expandafter\addplot\expandafter+\expandafter[\colo, domain = 0:2*pi]
      ({(exp(x) + exp(-x)) / 2 * cos(deg(\v))},
      {(exp(x) - exp(-x)) / 2 * sin(deg(\v))});

I want v to be a multiple of pi but

ERROR: Package PGF Math Error: Unknown operator `p' or `pi' (in '(exp(x) + exp(-x)\
) / 2 * cos(deg(7pi/4))').
share|improve this question
up vote 6 down vote accepted

should have a *

share|improve this answer
Some of the plots are appearing dashed when that isn't an option. Do you know why that would be? I had to change the domain to -5:5 or else there was a dimension too large error. – dustin Sep 5 '13 at 22:14
@dustin by default, from the sixth \addplot on, the line changes to a dashed style. To override this, add the solid option: [\colo, solid, domain = 0:2*pi] – Gonzalo Medina Sep 5 '13 at 22:38
@GonzaloMedina good job you answered that, my knowledge of pgf_anything_ is somewhat sketchy:-) – David Carlisle Sep 5 '13 at 22:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.