使用以下代码,我可以绘制抛物线 y=x^2,但无法绘制抛物线 x=y^2,显示一些错误

使用以下代码,我可以绘制抛物线 y=x^2,但无法绘制抛物线 x=y^2,显示一些错误

使用以下代码,我可以绘制抛物线 y=x^2,但无法绘制抛物线 x=y^2,显示一些错误,请帮忙。

\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}

答案1

添加variable=\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[black, line width = 0.50mm]   plot[smooth,domain= -2:2,variable=\y] (\y,  {(\y)^2});
\end{tikzpicture}
\end{document}

您也可以调用 plot 变量\CuteFurryRodent,您仍然会得到

\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}

在此处输入图片描述

你可能想交换 x 和 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}

在此处输入图片描述

这里也可以使用parabola bend

\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}

相关内容