1

There is a graph made of two addplot commands
enter image description here
But the arrows must be in the same direction (the way of the top one), and the axis are gone (or made transparent). The two sections are two separate functions not one (thats why the arrows isnt in the same direction). So how:

  • Can the arrows be in the same direction (either adjusting the decoration section or making the parabola runs continuosly)
  • How to make the axis appear?

Code in https://pastebin.com/W77g6Wtj, too the code option here was not working right for me at the time.

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

\begin{flushleft}
          \begin{tikzpicture}[scale=0.7,decoration={markings,
mark=at position 0.5cm with {\arrow[line width=1pt]{>}},
mark=at position 2cm with {\arrow[line width=1pt]{>}},
mark=at position 7.85cm with {\arrow[line width=1pt]{>}},
mark=at position 9cm with {\arrow[line width=1pt]{>}}
}]
        \begin{axis}[
            axis lines=middle,
            axis equal,
            samples = 200,
            xlabel = {$x$},
            ylabel = {$y$},
            xmin=-4,xmax=4,ymin=-5,ymax=5,
            ]
            \addplot[red,postaction=decorate]{sqrt(x+1)+2} node[pos=1,below]{$ $};
            \addplot[red,postaction=decorate]{-1*(sqrt(x+1)-2)} node[pos=1,below]{$ $};
            \draw[fill=red] (-1,2) circle (0.2);
            \draw[dashed,color=blue] (axis cs:0,2) -- (axis cs:-1,2);

            \end{axis}
            \end{tikzpicture}
    
            \end{flushleft}


\end{document}

2 Answers 2

4

With pgfplots and use of the parametric function:

\documentclass[border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\usetikzlibrary{arrows.meta,
                bending,
                decorations.markings}

\begin{document}
    \begin{tikzpicture}[
         > = {Straight Barb[scale=0.8, bend]},
->-/.style = {decoration={markings,% switch on markings
                          mark=between positions 0.1 and 0.9 step 0.25
                          with {\arrow[line width=1pt]{>}}
                          },
              postaction={decorate}, draw=red, thick
             },
lbl/.style = {font=\scriptsize, text=black, inner sep=1pt,
              near end, sloped, above}
                        ]%
\begin{axis}[
declare function = {f(\t)=((\t-2)^2-1);}, % (x,sqrt(x)) -> (x^2,x)  
    axis lines=middle,
    axis equal,
    xlabel = {$x$},
    ylabel = {$y$},
    xmin=-2.5, xmax=4.5,
    ymin=-2.5, ymax=4.5,
    ticklabel style={font=\footnotesize},
    domain=-0.5:4.5, samples = 200,
            ]
\addplot [->-] ({f(x)},x) 
            node[lbl]{$\sqrt{(x+1)}+2$};
\fill[red] (-1,2) circle[radius=2pt];
\draw[densely dashed,blue] (0,2) -- (-1,2);
    \end{axis}
    \end{tikzpicture}
\end{document}

enter image description here

2

enter image description here

I propose a solution using only the plot path operation and not addplot. You can work more for the axes, but it is maybe easier from the point of view of the decoration.

  • Even if you go back to pgfplots, draw a parametric curve rather than two graphs.
  • Include the decoration in a postaction. By the way, a minimal correction of your code would be to define two decorations and use one for each branch. The second one must have the arrow reversed, {<}.

The code

\documentclass[11pt, margin=1cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\begin{document}

\tikzset{
  flow/.style={%
    decorate,
    decoration={markings,
      mark=between positions .1 and .9 step{#1} with {%
        \arrow[line width=1pt]{>}}
    }
  }
}

\begin{tikzpicture}[every node/.style={scale=.8}]
  \draw[->] (-2.2, 0) -- (6.5, 0) node[above right] {$x$};
  \draw[->] (0,-4.2) -- (0, 4.5) node[above left] {$y$};
  \foreach \i in {-2, 2, 4, 6}{%
    \draw (\i, 2pt) -- ++(0, -4pt) node[below] {$\i$};
  }
  \foreach \i in {-4, -2, 2, 4}{%
    \draw (2pt, \i) -- ++(-3pt, 0) node[left] {$\i$};
  }

  \draw[red, thick, postaction={flow={.265}}]
  plot[domain=-.6:4.6] ({(\x-2)*(\x-2)-1}, \x-.1);
\end{tikzpicture}

\end{document}

You must log in to answer this question.

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