使用以下程式碼,我能夠繪製拋物線 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}
你也可以呼叫繪圖變量\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}