# pgfplots: changing dashed line dash locations

Is it possible to have one set of dashed lines fill the gap of another set?

The black is just barely sticks out from the purple. I would like the black to fill the gap in the purple.

\documentclass[tikz, convert = false, dvipsnames]{standalone}
\usepackage{mathtools}
\usepackage{pgfplots}
\pgfplotsset{compat = 1.8}
%\usepackage[dvipsnames]{xcolor}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
samples = 500,
no marks,
xlabel = $\scriptstyle x$,
ylabel = $\scriptstyle y$,
axis lines = middle,
xmin = -5,
xmax = 5,
ymin = -5,
ymax = 5,
legend style = {
at = {(-.35, 1)},
anchor = north west}
]
\foreach \u/\col in {0/red, 1/blue}{
({(exp(\u) + exp(-\u)) / 2 * cos(deg(x))},
{(exp(\u) - exp(-\u)) / 2 * sin(deg(x))});
}

\foreach \v/\colo in {0/OliveGreen, {pi/4}/Yellow, {pi/2}/RedOrange,
{3*pi/4}/Black, {5*pi/4}/Purple, {3*pi/2}/White,
{7*pi/4}/Brown}{
({(exp(x) + exp(-x)) / 2 * cos(deg(\v))},
{(exp(x) - exp(-x)) / 2 * sin(deg(\v))});
}

\legend{$u = 0$\\ $u = 1$\\ $v = 0$\\ $v = \pi / 4$\\ $v = \pi / 2$\\
$v = 3\pi / 4$\\ $v = 5\pi / 4$\\ $v = 3\pi / 2$\\ $v = 7\pi / 4$\\};
\end{axis}
\end{tikzpicture}
\end{document}

-
There is an option called dash phase in the manual. –  percusse Sep 5 '13 at 23:12
@percusse do you know where it is? I searched dash phase, dashphase, and check all the dash but there was nothing about dash phase –  dustin Sep 6 '13 at 0:11
It's in the PGF manual. –  percusse Sep 6 '13 at 0:18
texdoc tikz. Manual for Version 2.10. section 15.3.2 page 157. –  Hans-Peter E. Kristiansen Sep 6 '13 at 0:22
@percusse I tried many different options but there hasn't been a significant change. Are there any examples for doing such task? –  dustin Sep 6 '13 at 0:50

Using dash pattern=on <length> off <length> you can give a uniform pattern for the dashed lines (gaps and strokes of the same length given by <length>); then all you have to do is to use dash phase=<length> to shift the dashed pattern for one of the plots; here's an illustration using a simplified version of your code:

\documentclass[tikz, convert = false, dvipsnames]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat = 1.8}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
no marks,
xlabel = $\scriptstyle x$,
ylabel = $\scriptstyle y$,
axis lines = middle,
xmin = -5,
xmax = 5,
ymin = -5,
ymax = 5,
legend style = {
at = {(-.35, 1)},
anchor = north west}
]
\addplot+[ultra thick,cyan,dashed,dash pattern=on 8pt off 8pt,domain = -5:5] {x};
\addplot+[ultra thick,orange,dashed,dash pattern=on 8pt off 8pt,dash phase=8pt,domain = -5:5] {x};
\end{axis}
\end{tikzpicture}
\end{document}


And, of course, the simplest solution is to have one solid line and superimpose the dashed one:

\documentclass[tikz, convert = false, dvipsnames]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat = 1.8}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
no marks,
xlabel = $\scriptstyle x$,
ylabel = $\scriptstyle y$,
axis lines = middle,
xmin = -5,
xmax = 5,
ymin = -5,
ymax = 5,
legend style = {
at = {(-.35, 1)},
anchor = north west}
]
\addplot+[ultra thick,orange,dashed,dash pattern=on 8pt off 8pt,dash phase=8pt,domain = -5:5] {x};
\end{axis}
\end{tikzpicture}
\end{document}


Here, incorporating this last approach to (part of) the original \foreach (I used orange and Purple since Black and Purple don't produce enough contrast):

\documentclass[tikz, convert = false, dvipsnames]{standalone}
\usepackage{mathtools}
\usepackage{pgfplots}
\pgfplotsset{compat = 1.8}
%\usepackage[dvipsnames]{xcolor}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
samples = 500,
no marks,
xlabel = $\scriptstyle x$,
ylabel = $\scriptstyle y$,
axis lines = middle,
xmin = -5,
xmax = 5,
ymin = -5,
ymax = 5,
legend style = {
at = {(-.35, 1)},
anchor = north west}
]
\foreach \u/\col in {0/red, 1/blue}{
({(exp(\u) + exp(-\u)) / 2 * cos(deg(x))},
{(exp(\u) - exp(-\u)) / 2 * sin(deg(x))});
}

\foreach \v/\colostyle in {{3*pi/4}/{orange,solid}, {5*pi/4}/{Purple,dashed,thick}}{
({(exp(x) + exp(-x)) / 2 * cos(deg(\v))},
{(exp(x) - exp(-x)) / 2 * sin(deg(\v))});
}

\end{axis}
\end{tikzpicture}
\end{document}


And now using dahed for both paths, and changing the pattern and phase:

\documentclass[tikz, convert = false, dvipsnames]{standalone}
\usepackage{mathtools}
\usepackage{pgfplots}
\pgfplotsset{compat = 1.8}
%\usepackage[dvipsnames]{xcolor}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
samples = 500,
no marks,
xlabel = $\scriptstyle x$,
ylabel = $\scriptstyle y$,
axis lines = middle,
xmin = -5,
xmax = 5,
ymin = -5,
ymax = 5,
legend style = {
at = {(-.35, 1)},
anchor = north west}
]
\foreach \u/\col in {0/red, 1/blue}{
({(exp(\u) + exp(-\u)) / 2 * cos(deg(x))},
{(exp(\u) - exp(-\u)) / 2 * sin(deg(x))});
}

\foreach \v/\colostyle in {{3*pi/4}/{orange,dashed,dash pattern=on 8pt off 8pt}, {5*pi/4}/{Purple,dashed,dashed,dash pattern=on 8pt off 8pt,dash phase=14pt,thick}}{
({(exp(x) + exp(-x)) / 2 * cos(deg(\v))},
{(exp(x) - exp(-x)) / 2 * sin(deg(\v))});
}

\end{axis}
\end{tikzpicture}
\end{document}


-
Would it work so easily with a \foreach loop? –  dustin Sep 6 '13 at 2:15
@dustin I guess so, specially the second option; draw the first one solid and the second one dashed. I guess you'll need a third variable in your \foreach controlling the line style. –  Gonzalo Medina Sep 6 '13 at 2:21
@dustin please see my updated answer for an example using (part of) your \foreach. –  Gonzalo Medina Sep 6 '13 at 3:14
ædustin new update! –  Gonzalo Medina Sep 6 '13 at 3:34