![PGFPLOT 网格不完整,缺少上方和右侧的小网格](https://linux22.com/image/941259/PGFPLOT%20%E7%BD%91%E6%A0%BC%E4%B8%8D%E5%AE%8C%E6%95%B4%EF%BC%8C%E7%BC%BA%E5%B0%91%E4%B8%8A%E6%96%B9%E5%92%8C%E5%8F%B3%E4%BE%A7%E7%9A%84%E5%B0%8F%E7%BD%91%E6%A0%BC.png)
我正在用 pgfplot 包制作一个文件,我想让网格的两边都有完整的小网格线,这是我的尝试:
\documentclass{standalone}
\usepackage{filecontents}
\usepackage{amsmath}
\usepackage{tkz-euclide}
\usepackage{makecell}
\usepackage{ifthen}
\usepackage{pgfmath}
\usetikzlibrary
{
intersections, decorations.markings, angles,
quotes, calc, arrows, arrows.meta,shapes.geometric
}
\usepackage{tikz-3dplot}
\usetikzlibrary{calc,intersections,arrows.meta}
\usepackage{hyperref}
\usepackage{tikz,tikzscale}
\usepackage{chemfig,chemformula}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usepgfplotslibrary{fillbetween}
\begin{document}
\begin{filecontents}[overwrite]{fig2.tikz}
\begin{tikzpicture}
\pgfplotsset{
tick label style = {font = {\fontsize{11.25}{14}\selectfont}},
label style = {font = {\fontsize{11.25}{14}\selectfont}},
legend style = {font = {\fontsize{11.25}{14}\selectfont}},
}
\pgfplotsset{
outer axis line style={thick,},
grid = both,
tickwidth = 0.25cm,
set layers,
}
\begin{axis}[anchor=origin,
grid=both,
grid style={thin, draw=gray!20},
major grid style={thin,draw=gray!50},
minor x tick num={3},
minor y tick num={4},
minor tick length=0pt,
xmin=-4,xmax=4,
ymin=-16,ymax=4,
xlabel={$x$},
xlabel style={at={(ticklabel* cs:1)},anchor=west},
ylabel={$y$},
ylabel style={at={(ticklabel* cs:1)},anchor=south},
xtick={-3,...,3},
tickwidth=0.25cm,
major tick style={black,thick},
extra x ticks={-4,0,4},
extra x tick labels={,0,},
extra x tick style={grid=both,black,
major tick style={draw=none},
tick label style={anchor=north east,xshift=-.5*\pgfkeysvalueof{/pgfplots/major tick length}},},
ytick={-14,-12,...,2},
extra y ticks={-16, 4},
extra y tick style={grid=both,major tick style={draw=none},},
extra y tick labels={},
axis lines=middle,
scale only axis,
axis line style={>={Stealth[scale=1.2]},<->,thick},
samples=1000]
\addplot[domain=-4:4,draw=red,draw opacity=0.1,fill=red,fill opacity=0.1] {(3*x-2)*(x+3)}--(4,4)--(4,-16)--(-4,-16)--(-4,4)--cycle;
\addplot[domain=-4:4,draw=red,dashed] {(3*x-2)*(x+3)};
\end{axis}
\end{tikzpicture}
\end{filecontents}
\includegraphics[width=\linewidth]{fig2.tikz}
\end{document}