我只想为每个第二个 x 数据点设置网格。例如:我想要一条网格线,一个点 c 和 d,但不在两者之间。我希望我描述清楚了。这可能吗?我在文档中没有找到任何东西。
\documentclass[12pt]{article}
\usepackage{pgfplots}
\begin{document}
\begin{figure}
\begin{tikzpicture}
\begin{axis}[
width=15cm,
height=8cm,
xmin=0, xmax=9,
ymin=0, ymax=10,
ytick={0, 5},
yticklabels={0, x},
xtick={0, 0,5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6, 6.5, 7, 7.5, 8, 8.5, 9},
xticklabels={,a,, b,, c,, d,, e,, f,, g,, h,, i},
xmajorgrids={true},
x tick label style={rotate=45},
y label style={at={(axis description cs:0, 0.5)},anchor=south},
ylabel={estimation}
]
\legend{test1 a, test2 b}
\addplot coordinates {
(0, 0)
(1, 2)
(2, 2.2)
(3, 6)
(4, 6)
(5, 7.5)
(6, 7.5)
(7, 0)
(8, 4)
(9, 0)
};
\addplot [red] coordinates {(0, 5) (9, 5)};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
答案1
像这样?
\usepackage{pgfplots}
\begin{document}
\begin{figure}
\begin{tikzpicture}
\begin{axis}[
width=15cm,
height=8cm,
xmin=0, xmax=9,
ymin=0, ymax=10,
ytick={0, 5},
yticklabels={0, x},
xtick={0, ..., 9},
xticklabels={,a, b, c, d, e, f, g, h, i},
xmajorgrids={true},
minor x tick num=1,
x tick label style={rotate=45},
y label style={at={(axis description cs:0, 0.5)},anchor=south},
ylabel={estimation}
]
\legend{test1 a, test2 b}
\addplot coordinates {
(0, 0)
(1, 2)
(2, 2.2)
(3, 6)
(4, 6)
(5, 7.5)
(6, 7.5)
(7, 0)
(8, 4)
(9, 0)
};
\addplot [red] coordinates {(0, 5) (9, 5)};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}