我需要在 x 轴上添加一个额外的刻度,而不在新的 x 值处添加新的网格线,问题是我使用额外的刻度来获得完整的网格(这是在这个邮政) 其中线的起点和终点位于 x 轴和 y 轴的整数边界处。
\documentclass[border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=center,
grid=major,
grid style={dotted, cyan},
anchor=origin,
xlabel = $x$, ylabel =$y$, % Set the labels
xmin= -4, xmax= 4,
ymin=-4, ymax=4,
xtick={-3,-2,...,3},
ytick={-3,-2,...,3},
extra x ticks={-4,3.14, 4},
extra y ticks={-4, 4},
extra tick style={grid=major, grid style={dotted, cyan}},
extra x tick labels={,\hspace{.4em}$\pi$,},
extra y tick labels={},
color=cyan
]
\end{axis}
\end{tikzpicture}
\end{document}
答案1
要添加extra tick
x 轴,您可以使用
extra x tick style={grid=none},
在选项中:
\documentclass[border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=center,
grid=major,
grid style={dotted, cyan},
anchor=origin,
xlabel = $x$, ylabel =$y$, % Set the labels
xmin= -4, xmax= 4,
ymin=-4, ymax=4,
xtick={-3,-2,...,3},
ytick={-3,-2,...,3},
extra x ticks={-4,3.14, 4},
extra y ticks={-4, 4},
extra tick style={grid=major, grid style={dotted, cyan}},
extra x tick labels={,\hspace{.4em}$\pi$,},
extra y tick labels={},
extra x tick style={grid=none}, %% <<-----
color=cyan
]
\end{axis}
\end{tikzpicture}
\end{document}
这将使 x 轴两侧的最后网格线消失,可以使用以下方法绘制
\draw[dotted,cyan] (4,-4) -- (4,4)
(-4,-4) -- (-4,4);
\end{axis}
以下是 Gonzalo 提到的手动绘图选项:
\documentclass[border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=center,
grid=major,
grid style={dotted, cyan},
anchor=origin,
xlabel = $x$, ylabel =$y$, % Set the labels
xmin= -4, xmax= 4,
ymin=-4, ymax=4,
xtick={-3,-2,...,3},
ytick={-3,-2,...,3},
extra x ticks={-4, 4},
extra y ticks={-4, 4},
extra tick style={grid=major, grid style={dotted, cyan}},
extra x tick labels={},%,\hspace{.4em}$\pi$,},
extra y tick labels={},
%extra x tick style={grid=none}, %% <<-----
color=cyan
]
\draw[very thin,gray] (3.14,0.1) -- (3.14,-0.1)node[anchor=north west,inner xsep=0pt,text=cyan] {$\pi$};
\end{axis}
\end{tikzpicture}
\end{document}