我是 tikz 新手,一直在尝试创建不同的图形。我试图在轴周围得到一个漂亮的网格(如上图所示)。我遇到了麻烦。我尝试了几种方法,但似乎都没有用。
\begin{tikzpicture}
\draw[step=1cm,opacity=0.25] (0,0) grid (5.5,5.5);
\begin{axis}[
axis x line=center,
axis y line=center,
xmin=-10,xmax=10
ymin=-10.5,ymax=10
xtick={-5,-4,...,5},
ytick={-5,-4,...,5},
]
\end{axis}
任何帮助,将不胜感激。
答案1
您可以grid = both
像这样添加:
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\begin{document}
\footnotesize
\begin{tikzpicture}
\begin{axis}[
axis x line = center,
axis y line = center,
xmin = -5, xmax = 5,
ymin = -5, ymax = 5,
xtick = {-5,-4,...,5},
ytick = {-5,-4,...,5},
grid = both,
]
\addplot[mark=none,samples=250,thick]{x^3};
\end{axis}
\end{tikzpicture}
\end{document}