我想要像我一样在整个平面上设置网格,但我不想要坐标轴上的标签(x/y=1 处除外)或 MWE 中看到的空白处。我该如何实现这一点?
\documentclass[12pt]{article}
\usepackage{amsmath, amssymb}
\usepackage[usenames,dvipsnames,svgnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture} %y=x^-4
\begin{axis}[grid=both,
axis lines=middle,
ticklabel style={fill=white,font=\scriptsize},
x=0.4cm,y=0.4cm,clip=false,
xmin=-4,xmax=4,xtick={-3,-2,-1,1,2,3},xticklabels={,,,1,,},
ymin=-4,ymax=4,ytick={-3,-2,-1,1,2,3},yticklabels={,,,1,,},
xlabel=\(x\),ylabel=\(y\),
samples=200]
\addplot[domain=-4:-0.250,<->,>=latex] {x^-1};
\addplot[domain=0.250:4,<->,>=latex] {x^-1};
\node[label={270:{\(y=x^{-1}\)}},inner sep=4pt] at (axis cs:0,-4) {};
\end{axis}
\end{tikzpicture}
\end{document}
从而产生了这个。
答案1
删除 x 和 y 刻度标签并使用额外的 x/y 刻度。
\documentclass[12pt]{article}
\usepackage{amsmath, amssymb}
\usepackage[usenames,dvipsnames,svgnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture} %y=x^-4
\begin{axis}[grid=both,
axis lines=middle,
extra x tick style={ticklabel style={fill=white,font=\scriptsize},xticklabel={1}},
extra y tick style={ticklabel style={fill=white,font=\scriptsize},yticklabel={1}},
x=0.4cm,y=0.4cm,clip=false,
xmin=-4,xmax=4,xtick={-3,-2,-1,1,2,3},xticklabels={\empty},
ymin=-4,ymax=4,ytick={-3,-2,-1,1,2,3},yticklabels={\empty},
extra x ticks={1}, extra y ticks={1},
xlabel=\(x\),ylabel=\(y\),
samples=200]
\addplot[domain=-4:-0.250,<->,>=latex] {x^-1};
\addplot[domain=0.250:4,<->,>=latex] {x^-1};
\node[label={270:{\(y=x^{-1}\)}},inner sep=4pt] at (axis cs:0,-4) {};
\end{axis}
\end{tikzpicture}
\end{document}