# Drawing phase line for differential equations

How can one draw one of this pictures in latex with the simplest way and good looking output?

-
Your question leaves all the effort to our community, even typing the essentials of a TeX document such as \documentclass{}...\begin{document} etc. As it is, most of our users will be very reluctant to touch your question, and you are left to the mercy of our procrastination team who are very few in number and very picky about selecting questions. You can improve your question by adding a minimal working example (MWE) that more users can copy/paste onto their systems to work on. If no hero takes the challenge we might have to close your question. –  Adam Liter Apr 7 '14 at 3:33
And welcome to TeX.SX! –  Adam Liter Apr 7 '14 at 3:34

Here is a tikz solution. Using

\DrawHorizontalPhaseLine{0,2,4}{-0.5, 4.7}{1, 2.5}


and

\DrawVerticalPhaseLine[$y$]{0,2,4}{-0.5, 4.7}{1, 2.5}


yields:

The parameters to \DrawHorizontalPhaseLine are:

1. The optional axis label to be applied (defaults to no label).
2. The axis tick labels
3. The positions of the right arrows as a comma separated list.
4. The positions of the left arrows as a comma separated list.

As the arrows are added, we keep track of the \AxisMin and \AxisMax, and at the end a line is drawn to extend past that.

The \DrawVerticalPhaseLine macro accepts similar parameters for the up and down arrow locations.

## Code:

\documentclass[border=2pt]{standalone}
\usepackage{tikz}

\newcommand*{\TickSize}{2pt}%

\newcommand*{\AxisMin}{0}%
\newcommand*{\AxisMax}{0}%

\newcommand*{\DrawHorizontalPhaseLine}[4][]{%
% #1 = axis tick labels
% #2 = right arrows positions as CSV
% #3 = left arrow positions as CSV
\gdef\AxisMin{0}%
\gdef\AxisMax{0}%
\edef\MyList{#2}% Allows for #1 to be both a macro or not
\foreach \X in \MyList {
\draw  (\X,\TickSize) -- (\X,-\TickSize) node [below] {$\X$};
\ifnum\AxisMin>\X
\xdef\AxisMin{\X}%
\fi
\ifnum\AxisMax<\X
\xdef\AxisMax{\X}%
\fi
}

\edef\MyList{#3}% Allows for #2 to be both a macro or not
\foreach \X in \MyList {% Right arrows
\draw [->] (\X-0.1,0) -- (\X,0);
\ifnum\AxisMin>\X
\xdef\AxisMin{\X}%
\fi
\ifnum\AxisMax<\X
\xdef\AxisMax{\X}%
\fi
}

\edef\MyList{#4}% Allows for #3 to be both a macro or not
\foreach \X in \MyList {% Left arrows
\draw [<-] (\X-0.1,0) -- (\X,0);
\ifnum\AxisMin>\X
\xdef\AxisMin{\X}%
\fi
\ifnum\AxisMax<\X
\xdef\AxisMax{\X}%
\fi
}

\draw  (\AxisMin-1,0) -- (\AxisMax+1,0) node [right] {#1};
}%

\newcommand*{\DrawVerticalPhaseLine}[4][]{%
% #1 = axis tick labels
% #2 = up arrows positions as CSV
% #3 = down arrow positions as CSV
\gdef\AxisMin{0}%
\gdef\AxisMax{0}%
\edef\MyList{#2}% Allows for #1 to be both a macro or not
\foreach \X in \MyList {
\draw  (-\TickSize,\X) -- (\TickSize,\X) node [right] {$\X$};
\ifnum\AxisMin>\X
\xdef\AxisMin{\X}%
\fi
\ifnum\AxisMax<\X
\xdef\AxisMax{\X}%
\fi
}

\edef\MyList{#3}% Allows for #2 to be both a macro or not
\foreach \X in \MyList {% Up arrows
\draw [->] (0,\X-0.1) -- (0,\X);
\ifnum\AxisMin>\X
\xdef\AxisMin{\X}%
\fi
\ifnum\AxisMax<\X
\xdef\AxisMax{\X}%
\fi
}

\edef\MyList{#4}% Allows for #3 to be both a macro or not
\foreach \X in \MyList {% Down arrows
\draw [<-] (0,\X+0.1) -- (0,\X);
\ifnum\AxisMin>\X
\xdef\AxisMin{\X}%
\fi
\ifnum\AxisMax<\X
\xdef\AxisMax{\X}%
\fi
}

\draw  (0,\AxisMin-1) -- (0,\AxisMax+1) node [above] {#1};
}%

\begin{document}
\begin{tikzpicture}[thick]
\DrawVerticalPhaseLine[$y$]{0,2,4}{-0.5, 4.7}{1, 2.5}%
\end{tikzpicture}
%
\begin{tikzpicture}[thick]
\DrawHorizontalPhaseLine[$y$]{0,2,4}{-0.5, 4.7}{1, 2.5}%
\end{tikzpicture}
\end{document}

-
Thanks a lot. How does it make to vertical line mode? How does create label $Y$ for axis? –  bigli Apr 7 '14 at 3:58
@bigli: Updated to have a vertical version as well, and an optional parameter to specify the label. –  Peter Grill Apr 7 '14 at 4:04
I can update your code for vertical version. But I can't create label for axis in both of them. Could you please hint me? –  bigli Apr 7 '14 at 4:25
@bigli: The updated solution provides an optional first parameter which specifies the label. –  Peter Grill Apr 7 '14 at 8:06

The vertical phase line shows all up arrows. It's just a matter of changing a plus sign to a minus sign. Change this part:

\edef\MyList{#4}% Allows for #3 to be both a macro or not
\foreach \X in \MyList {% Down arrows
\draw [<-] (0,\X+0.1) -- (0,\X);


to

\edef\MyList{#4}% Allows for #3 to be both a macro or not
\foreach \X in \MyList {% Down arrows
\draw [<-] (0,\X-0.1) -- (0,\X);

-