\documentclass{amsart}
\usepackage{tikz}
\usepackage{pst-plot}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}
\draw[->] (-3.5,0) -- (3.5,0) node[right] {$x$};
\draw[->] (0,-3.5) -- (0,3.5) node[above] {$y$};
\draw[scale=1,domain=-2:2,smooth,variable=\x,blue] plot ({\x},{\x*\x - 1});
\draw[scale=1,domain=-2:2,smooth,variable=\y,red] plot ({\y},{\y});
\end{tikzpicture}
\end{document}
我想用通常的整数值对 x 轴和 y 轴进行编号。我该如何实现?
答案1
一种方法是用循环定义的刻度完成轴foreach
:
%\documentclass{amsart}
%\usepackage{tikz}
\documentclass[tikz,margin=10pt]{standalone}
%\usepackage{pst-plot}
%\usetikzlibrary{decorations.markings}
%\usetikzlibrary{arrows}
\begin{document}
另一种方法是绘制带有pgfplots
刻度的图表,并使用轴的选项进行定义:
%\documentclass{amsart}
%\usepackage{tikz}
\documentclass[margin=10pt]{standalone}
%\usepackage{pst-plot}
\usepackage{pgfplots}
%\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xlabel={$x$},
ylabel={$y$},
axis lines=center,
xmin=-3.5, xmax=3.5,
ymin=-3, ymax=3
]
\addplot[domain=-2:2,smooth,variable=\x,red] {\x*\x - 1};
\addplot[domain=-2:2,smooth,variable=\y,blue] {\y};
\end{axis}
\end{tikzpicture}
\end{document}