我正在尝试使用 pgfplots 制作一个图表,其中 y 刻度从 0 均匀分布到 100,因此:0、10、20 等。但是当我创建此图表时,y 刻度立即从 0 变为 30,之后它们再次以 10 的距离均匀分布。我怎样才能使刻度从 0 变为 10 再变为 20 等而不跳过一些刻度?我使用的代码是:
\begin{tikzpicture}
\begin{axis}[
axis lines = left,
domain = 0:35,
range = 0:100,
xlabel = $t(m)$,
ylabel = $T(\degree C)$,
grid=major,
ytick distance=10,
legend pos=north west]
\addplot coordinates {
(0, 24)
(0.5, 24.5)
(1, 25)
(1.5, 26.5)
(2, 28)
(2.5, 30)
(3, 33)
(4, 37)
(5, 40.3)
(6, 44)
(7, 48)
(8, 51.8)
(9, 54.2)
(10, 58.9)
(11, 61)
(12, 64)
(13, 66.3)
(14, 69)
(15, 71.1)
(16, 73.4)
(17, 75.8)
(18, 79.5)
(19, 80.6)
(20, 82.1)
(21, 85)
(22, 86.9)
(23, 88.5)
(23.95, 90)
(24.45, 88.5)
(24.95, 87.4)
(25.45, 86.6)
(25.95, 85.6)
(26.45, 84.7)
(26.95, 84)
(27.95, 82.1)
(28.95, 80.6)
(29.95, 79)
(30.95, 78)
(31.95, 76.5)
(32.95, 76.1)
(33.95, 74)
};
\addlegendentry{meetwaardes}
\end{axis}
\end{tikzpicture}
提前感谢您的帮助!
答案1
如果您希望有完整的 y 轴,则需要定义ymin=0
和:ymax=100
\documentclass[margin=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepackage{siunitx}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines = left,
domain = 0:35,
range = 0:100,
xlabel = $t$ (m),
ylabel = $T$ (\si{\celsius}),
grid=major,
ymin=0, ymax=100,
legend pos=north west]
\addplot coordinates {
(0, 24)
(0.5, 24.5)
(1, 25)
(1.5, 26.5)
(2, 28)
(2.5, 30)
(3, 33)
(4, 37)
(5, 40.3)
(6, 44)
(7, 48)
(8, 51.8)
(9, 54.2)
(10, 58.9)
(11, 61)
(12, 64)
(13, 66.3)
(14, 69)
(15, 71.1)
(16, 73.4)
(17, 75.8)
(18, 79.5)
(19, 80.6)
(20, 82.1)
(21, 85)
(22, 86.9)
(23, 88.5)
(23.95, 90)
(24.45, 88.5)
(24.95, 87.4)
(25.45, 86.6)
(25.95, 85.6)
(26.45, 84.7)
(26.95, 84)
(27.95, 82.1)
(28.95, 80.6)
(29.95, 79)
(30.95, 78)
(31.95, 76.5)
(32.95, 76.1)
(33.95, 74)
};
\addlegendentry{meetwaardes}
\end{axis}
\end{tikzpicture}
\end{document}
另一种解决方案是使用上面的 MWErestrict y to domain=0:100,
代替ymin=0, ymax=100,
。在这种情况下,结果是: