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

I know that you can make a dashed line in pgfplots using the \addplot[dashed] option. However, the line that produces isn't dashed the way I'd like.

I found \pgfsetdash in the documentation for PGF, but I can't figure out how to use it on just one \addplot. If I include it anywhere within the tikzpicture environment, it changes all of the lines, including the axes. I thought that adding a second \pgfsetdash would change the style, but it doesn't seem to have an effect.

Any advice for creating custom dash styles in PGF plots?

share|improve this question
up vote 21 down vote accepted

You can use the key dash pattern=<pattern> to define a dash pattern in an \addplot:


\addplot [dash pattern=on 4pt off 1pt on 4pt off 4pt] {x^2};

share|improve this answer

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.