1

With the following code, I am able to draw a parabola y=x^2, but unable to draw parabola x=y^2, showing some error, please help.

\documentclass{article}
\usepackage{tikz,pgfplots}
%\usepackage[x11names]{xcolor}
\usepackage{tikz}
\usetikzlibrary{intersections}
\pgfdeclarelayer{bg}    % declare background
\pgfsetlayers{bg,main}  % order of layers (main = standard layer)
\pgfplotsset{compat=1.13}
\usepackage{amsmath}
\usetikzlibrary{positioning}





\begin{document}



\begin{tikzpicture}[domain=0:2, scale = 0.75]
\draw(-4,0)--(4,0);
\draw (0,-4)--(0,4);
\draw[black, line width = 0.50mm]   plot[smooth,domain=-2:2] (\x, {(\x)^2});

\draw[black, line width = 0.50mm]   plot[smooth,domain= -2:2] (\y,  {(\y)^2});
\end{tikzpicture}
\end{document}
Bernard
  • 271,350
Sachin
  • 259
  • 1
  • 6

1 Answers1

3

Add variable=\y. The result is obviously the same.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[domain=0:2, scale = 0.75]
\draw(-4,0)--(4,0);
\draw (0,-4)--(0,4);
%\draw[black, line width = 0.50mm]   plot[smooth,domain=-2:2] (\x, {(\x)^2});

\draw[black, line width = 0.50mm]   plot[smooth,domain= -2:2,variable=\y] (\y,  {(\y)^2});
\end{tikzpicture}
\end{document}

You could also call the plot variable \CuteFurryRodent, and you will still get

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[domain=0:2, scale = 0.75]
\draw(-4,0)--(4,0);
\draw (0,-4)--(0,4);
\draw[black, line width = 0.50mm]   
plot[smooth,domain= -2:2,variable=\CuteFurryRodent] (\CuteFurryRodent,  {(\CuteFurryRodent)^2});
\end{tikzpicture}
\end{document}

enter image description here

You may want to swap the roles of x and y,

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[domain=0:2, scale = 0.75]
\draw(-4,0)--(4,0);
\draw (0,-4)--(0,4);
\draw[black, line width = 0.50mm]   plot[smooth,domain=-2:2] (\x, {(\x)^2});

\draw[blue,dashed, line width = 0.50mm]   plot[smooth,domain= -2:2,variable=\y]
 ( {(\y)^2},\y);
\end{tikzpicture}
\end{document}

enter image description here

One could also use parabola bend here.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[domain=0:2, scale = 0.75]
\draw(-4,0)--(4,0);
\draw (0,-4)--(0,4);
\draw[black, line width = 0.50mm]  (-2,4) parabola bend (0,0) (2,4);

\draw[blue,dashed, line width = 0.50mm,rotate=-90]  (-2,4) parabola bend (0,0) (2,4);
\end{tikzpicture}
\end{document}