4

How does one draw a horizontal parabola, left or right oriented? I can easily draw:

\draw[blue, line width=1.75pt, domain=-2.00 : 3.00, samples=1500] plot[smooth](\x, {\x*\x - \x - 2});

and even trick a horizontal parabola in origin using two radicals:

\draw[magenta, line width=1.75pt, domain={0.00}:{3.0}, samples=1500] plot[smooth]( \x, {pow(\x, 0.5)} );
\draw[magenta, line width=1.75pt, domain={0.00}:{3.0}, samples=1500] plot[smooth]( \x, {- pow(\x, 0.5)} );

But I cannot make it do this (true horizontal parabola):

\draw[red, line width=1.75pt, domain={-4.10}:{4.0}, samples=500] plot[smooth]( \y, {\y*\y - \y - 2} );

Any idea? Here's my MWE:

\documentclass{standalone}

\usepackage{mathtools} %includes amsmath
\usepackage{mathabx}
\usepackage{tikz}
\usetikzlibrary{patterns,calc,arrows}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\usepgfplotslibrary{fillbetween}

\begin{document}

\begin{tikzpicture}[>=triangle 45, cap=round]

\draw[->] (-4.0,0) -- (4.0,0); % Ox
\node[below] at (4.0, 0.0) {\textit{x}};
\node at (-0.2,-0.3) {\textit{0}};
\draw[->] (0,-4.0) -- (0,4.0); % Oy
\node[left] at (0.0,4.0) {\textit{f(x)}};
\filldraw [red] (0.00, 0.00) circle(3pt);

\draw[blue, line width=1.75pt, domain=-2.00 : 3.00, samples=1500] plot[smooth](\x, {\x*\x - \x - 2});
%\draw[red, line width=1.75pt, domain={-4.10}:{4.0}, samples=500] plot[smooth]( \y, {\y*\y - \y - 2} );

\draw[magenta, line width=1.75pt, domain={0.00}:{3.0}, samples=1500] plot[smooth]( \x, {pow(\x, 0.5)} );
\draw[magenta, line width=1.75pt, domain={0.00}:{3.0}, samples=1500] plot[smooth]( \x, {- pow(\x, 0.5)} );

\end{tikzpicture} 

\end{document}
Diegis
  • 1,107
  • Apply rotate=90 or rotate=270 to one of the vertical ones. – Gonzalo Medina Oct 13 '15 at 23:32
  • 2
    Parameterize it \draw[red, line width=1.75pt, domain={-4.10}:{4.0}, samples=500] plot[smooth]({\x*\x - \x - 2},\x ); – Guho Oct 13 '15 at 23:40
  • @Guho You should turn your comment into a proper answer. – Gonzalo Medina Oct 13 '15 at 23:42
  • @GonzaloMedina Looks like @jarauh beat me to it. The link I posted in the comment has your proposed method, parameterization, and swapaxes. – Guho Oct 13 '15 at 23:51
  • @Guho Thank you, I am using your one-liner for the solution to this question -- if you make it an answer I will flag it accordingly. I did not know you can parametrize things just by switching the order around, awesome! Thank you all for your answers, but I am not that advanced, and right now I can't spend as much time as I would like studying these tikz and all the plotting routines. But I am saving them for later study, thank you again. – Diegis Oct 14 '15 at 01:33

3 Answers3

4

There are numerous approaches, as summarized by the answers provided in Plot inverse function in pgfplots.

Given your format, you could just switch the order of the arguments (and substitute \x for \y):

\draw[red, line width=1.75pt, domain={-4.10}:{4.0}, samples=500] plot[smooth]({\x*\x - \x - 2},\x );

which, if inserted in place of the commented line in your MWE, yields

enter image description here

Guho
  • 6,115
3

Actually not too difficult (if I understood correctly what you want):

\begin{tikzpicture}
  \begin{axis}
    \addplot+[domain=-10:10,samples=50] ({x^2},{x});
  \end{axis}
\end{tikzpicture}

enter image description here

jarauh
  • 2,762
  • 15
  • 27
1

For the parabola with equation $x=y^2-y-2$, with pst-plot, you have \parametricplot{init}{end}{f(t) | g(t)}:

\documentclass[x11names]{article}
\usepackage{fourier}
\usepackage{pst-plot, pst-node}
\usepackage{auto-pst-pdf}
\pagestyle{empty}
\begin{document}

\psset{algebraic=true, arrowsize=3pt,arrowinset=0.15, plotpoints=500, linecolor=LightSteelBlue3}
\begin{pspicture*}(-3,-4)(8,4.5)
    \psaxes[ticks=none, labels=none, arrows=->](0,0)(-3,-4)(8,4.5)[$x$, -110][$y$,-135]
    \parametricplot[linecolor =IndianRed3, linewidth=1.2pt]{-4}{4}{t^2-t-2 | t}
    \dotnode[linecolor =IndianRed3](-2.25, 0.5){S}\pnodes(-2.25,0){Sx}(0,0.5){Sy}
    \psset{linewidth = 0.4pt, linestyle=dashed}
    \ncline{S}{Sx}\ncline{S}{Sy}
    \uput[d](Sx){$-\frac52$}\uput[r](Sy){$1$}
\end{pspicture*}

\end{document} 

enter image description here

Bernard
  • 271,350