我正在用 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}