我正在尝试向具有许多点的曲线添加一些标记,如下所示,但不诉诸第二个添加图:
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot[color=red,no markers] coordinates {
(2,-1.8559703)
(2.5,-2.8559703)
(3,-3.5301677)
(3.5,-4.01677)
(4,-4.3050655)
(4.5,-4.813136)
(5,-5.1413136)
(5.5,-5.7322865)
(6,-6.0322865)
(6.5,-6.675052)
(7,-6.9675052)
(7.5,-7.975052)
(8,-8.9377747)
};
\addplot[color=red, only marks] coordinates {
(2,-1.8559703)
(4,-4.3050655)
(6,-6.0322865)
(8,-8.9377747)
};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
您有多个键可以控制应绘制哪些标记:
您可以使用
mark repeat=<number>
;这允许仅绘制每个nth
标记,其中n
提供的值为<number>
。mark phase=<number>
;使用后添加此项mark repeat
来控制标记的起点。还有
mark indices={<index list>}
;使用它来指定应该绘制的标记的索引列表。
显示这些键实际作用的完整示例(第一个示例给出了您在问题中请求的标记模式):
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot+[color=red,mark repeat=4] coordinates {
(2,-1.8559703)
(2.5,-2.8559703)
(3,-3.5301677)
(3.5,-4.01677)
(4,-4.3050655)
(4.5,-4.813136)
(5,-5.1413136)
(5.5,-5.7322865)
(6,-6.0322865)
(6.5,-6.675052)
(7,-6.9675052)
(7.5,-7.975052)
(8,-8.9377747)
};
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}
\addplot+[color=red,mark repeat=3,mark phase=2] coordinates {
(2,-1.8559703)
(2.5,-2.8559703)
(3,-3.5301677)
(3.5,-4.01677)
(4,-4.3050655)
(4.5,-4.813136)
(5,-5.1413136)
(5.5,-5.7322865)
(6,-6.0322865)
(6.5,-6.675052)
(7,-6.9675052)
(7.5,-7.975052)
(8,-8.9377747)
};
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}
\addplot+[color=red,mark indices={1,5,9}] coordinates {
(2,-1.8559703)
(2.5,-2.8559703)
(3,-3.5301677)
(3.5,-4.01677)
(4,-4.3050655)
(4.5,-4.813136)
(5,-5.1413136)
(5.5,-5.7322865)
(6,-6.0322865)
(6.5,-6.675052)
(7,-6.9675052)
(7.5,-7.975052)
(8,-8.9377747)
};
\end{axis}
\end{tikzpicture}
\end{document}