以下 MWE
\documentclass[beamer,crop]{standalone}
\usepackage{times}
\usepackage{pgfplots,xparse}
\pgfplotsset{
compat=1.17, % Specify the compatibility version
nice_axis/.style={
xlabel={$t/T_c$},
ylabel={$p_{BOC \left( 1,1 \right)}\left( t \right)\cdot \sqrt{T_c}$},
% title={Triangle Function},
grid=both,
axis lines=box,
samples=101,
domain=-2:2,
xmin=-1,
xmax=1,
ymax=1.2,
ymin=-1.2,
ytick={-1, -0.8, ..., 1},
legend pos=outer north east,
}
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
nice_axis,
]
\addplot[black, thick, mark=none] coordinates {
(-1,0)
(-0.5,0)
(-0.5,1)
(0,1)
(0,-1)
(0.5,-1)
(0.5,0)
(1,0)
};
\end{axis}
\end{tikzpicture}
\end{document}
收益
据我所知,在其他 pot 中,这是由于舍入误差造成的。如何设置ytick
才能避免出现零精度误差?我试过了此解决方案但它似乎table
只对...有效。
答案1
你可以yticklabel
四舍五入
yticklabel style = {/pgf/number format/fixed},
完成 MWE:
\documentclass[beamer,crop]{standalone}
\usepackage{times}
\usepackage{pgfplots,xparse}
\pgfplotsset{
compat=1.18, % Specify the compatibility version
nice_axis/.style={
xlabel={$t/T_c$},
ylabel={$p_{BOC \left( 1,1 \right)}\left( t \right)\cdot \sqrt{T_c}$},
% title={Pulse Function},
grid=both,
axis lines=box,
domain=-1:1,
ytick={-1, -0.8, ..., 1},
yticklabel style = {/pgf/number format/fixed},
xmin=-1, xmax=1,
legend pos=outer north east,
}
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[nice_axis]
\addplot[thick, mark=none] coordinates {
(-1,0)
(-0.5,0)
(-0.5,1)
(0,1)
(0,-1)
(0.5,-1)
(0.5,0)
(1,0)
};
\end{axis}
\end{tikzpicture}
\end{document}