将“每个第 n 个点”限制在一个域内

将“每个第 n 个点”限制在一个域内

我有一个情节很多数据点,但大多数图表不需要数据中的细节级别。

我怎样才能结合each nth pointrestrict expr to domain

我想each nth point=3在域x=0:9和之间应用x=28:36。最好同时绘制端点在x=36,因为否则盲目绘制每个第三个点会被跳过。

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}

\begin{axis}[%
width=8cm,
height=5cm,
scale only axis,
]
\addplot [
color=red,
solid,
forget plot
]
table[row sep=crcr]{
0 1\\
1 2\\
2 3\\
3 4\\
4 5\\
6 7\\
7 8\\
8 9\\
9 10\\
10 18\\
14 4\\
18 30\\
20 45\\
22 2\\
24 15\\
28 10\\
29 9\\
30 8\\
31 7\\
32 6\\
33 5\\
34 4\\
35 3\\
36 2\\
};
\end{axis}
\end{tikzpicture}%
\end{document}

答案1

是這樣嗎?

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\pgfplotstableread{
0 1
1 2
2 3
3 4
4 5
6 7
7 8
8 9
9 10
10 18
14 4
18 30
20 45
22 2
24 15
28 10
29 9
30 8
31 7
32 6
33 5
34 4
35 3
36 2
}\mytable
\begin{document}
\begin{tikzpicture}

\begin{axis}[%
width=8cm,
height=5cm,
scale only axis,
]
\addplot [
color=red,
mark=*,
solid,
each nth point={3},
restrict x to domain=0:9,
forget plot
]
table[row sep=crcr]{\mytable};
\addplot [
color=red,
mark=*,
solid,
each nth point={3},
restrict x to domain=28:36,
forget plot
]
table[row sep=crcr]{\mytable};
\end{axis}
\end{tikzpicture}%
\end{document}

在此处输入图片描述

相关内容