4

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

2
  • 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, 2014 at 3:33
  • And welcome to TeX.SX!
    – Adam Liter
    Apr 7, 2014 at 3:34

3 Answers 3

8

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:

Screenshot showing the same phase line both vertically and horizontally

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}
4
  • Thanks a lot. How does it make to vertical line mode? How does create label $Y$ for axis?
    – bigli
    Apr 7, 2014 at 3:58
  • @bigli: Updated to have a vertical version as well, and an optional parameter to specify the label. Apr 7, 2014 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, 2014 at 4:25
  • @bigli: The updated solution provides an optional first parameter which specifies the label. Apr 7, 2014 at 8:06
0

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);
0

A quick solution. This is the simplest as far as I know.

\begin{figure}
        \begin{tikzpicture}[scale=1]
        % Vertical line (the range of the real line)
\draw[thick, black] (0, -1.5) -- (0, 5.5);

% Equilibrium points
\fill[red] (0,0) circle (0.1) node[above left] {0};
\fill[red] (0,2) circle (0.1) node[above left] {2};
\fill[red] (0,4) circle (0.1) node[above left] {4};

% Directional arrows
%% below point 0 (attracting)
\draw[thick, ->, black, >=latex] (0, -1) -- (0, -0.2);
\draw[thick, ->, black, >=latex] (0, -1.5) -- (0, -1);

%% between 2 and 0 (attracting to 0)
\draw[thick, ->, black, >=latex] (0, 1.9) -- (0, 1);
\draw[thick, ->, black, >=latex] (0, 0.8) -- (0, 0.3);

%% between 4 and 2 (2 as a saddle)
\draw[thick, ->, black, >=latex] (0, 3.9) -- (0, 3);
\draw[thick, ->, black, >=latex] (0, 2.8) -- (0, 2.2);

%% above point 4 (away from 4)
\draw[thick, ->, black, >=latex] (0, 4.1) -- (0, 4.5);
\draw[thick, ->, black, >=latex] (0, 4.5) -- (0, 5.3);
    \end{tikzpicture}
\end{figure}

Output

vertical phase line

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .