我有以下乳胶代码,但不幸的是无法获得我所选择的 ytick。
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{center}
\begin{tikzpicture}
\begin{axis}[
xlabel=Trail Run \#,
ylabel=Task completion time,
xtick={0, 4, 8, 12, 16, 20},
ytick={0, 1, 2, 3, 4, 5, 6},
legend style={
at={(0.5,0.5)},
anchor=center}]
\addplot[smooth,color=black,mark=*]
plot coordinates {
(1, 5.372137)
(2, 5.401571)
(3, 5.418153)
(4, 5.409281)
(5, 5.440709)
(6, 5.425516)
(7, 5.366961)
(8, 5.392147)
(9, 5.345825)
(10, 5.366253)
(11, 5.320773)
(12, 5.373887)
(13, 5.338346)
(14, 5.322246)
(15, 5.399925)
(16, 5.349757)
(17, 5.345629)
(18, 5.336819)
(19, 5.364673)
(20, 5.402730)
};
\addlegendentry{XY at 3x3}
\addplot[smooth,color=magenta,mark=*]
plot coordinates {
(1, 4.349543)
(2, 4.348597)
(3, 4.349540)
(4, 4.348221)
(5, 4.344659)
(6, 4.350545)
(7, 4.345121)
(8, 4.337458)
(9, 4.344044)
(10, 4.349293)
(11, 4.344615)
(12, 4.349939)
(13, 4.346299)
(14, 4.341717)
(15, 4.345412)
(16, 4.351933)
(17, 4.351421)
(18, 4.338126)
(19, 4.345590)
(20, 4.348072)
};
\addlegendentry{YX at 3x3}
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}
在这种情况下,我特意更改了图例的位置,而这并不是我真正想要的。我希望图例位于东南方向(我可以做到),但我希望 ytick 更像 — {0, 1, 2, 3, 4, 5, 6},因此我将两个图表放在彼此附近,并以终端“0”作为参考。
有什么想法吗?
答案1
由于您确实想控制最小和最大 y 值,因此您需要设置它们ymax=6, ymin=0
。添加这些选项可产生: