[Tex/LaTex] Custom Dashed Plot Lines in PGFPLots

pgfplots

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?

Best Answer

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

\documentclass{article}
\usepackage{pgfplots}
\begin{document}


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

\end{document}