我写了这篇文章:
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\begin{document}
\begin{center}
\begin{tikzpicture}[scale=1.5]
\draw[->,line width=1pt] (-2,0)--(2,0) node[right]{$y$};
\draw[->,line width=1pt] (0,-2)--(0,2) node[above]{$f(y)$};
\draw[blue,line width=1pt,domain=-2:2, samples=100] plot(\x,\x^2);
\end{tikzpicture}
\end{center}
\end{document}
但我得到了这张图片:
我该如何解决这个问题?我只想使用 tikz plot 命令,而不是 pgfplot 或其他命令。
谢谢
答案1
按照@projetmbc 在他的评论中的建议尝试或者
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\begin{document}
\begin{center}
\begin{tikzpicture}[scale=1.5]
\draw[->,line width=1pt] (-2,0)--(2,0) node[right]{$y$};
\draw[->,line width=1pt] (0,-0.5)--(0,4.5) node[above]{$f(y)$};
\draw[blue,line width=1pt,domain=-2:2, samples=100] plot(\x,{(\x)^2}); % <--- observe parenthesis
\end{tikzpicture}
\end{center}
\end{document}
答案2
PGF 图是一个不错的选择:
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ticks=none,
xlabel={\(y\)},
ylabel={\(f\big(y\big)\)}, xmin=-4,xmax=4,ymin=-4,ymax=4,
every axis plot/.append style={thick},
axis y line=center,
axis x line=center,
axis line style={-Triangle},
xlabel style={at=(current axis.right of origin), anchor=west},
ylabel style={at=(current axis.above origin), anchor=south},
]
\addplot[red,domain=-2:2,samples=500,thick]{x^2)};
\end{axis}
\end{tikzpicture}
\end{document}