
我有一個很長的 CSV 資料檔:
x,y1,y2...
1,v1,v1...
2,v2,v2...
....
我用來pgfplots
繪製所有的線條。我還想添加標記形狀。但問題是數據太密集,而且我的空間有限,所以標記黏在一起了。
我試過:
\addplot[blue, thin, mark=square, each nth point=20] table ...
但它也跳過了數據點。
我想要一條平滑的線,但只有幾個標記。我怎樣才能做到這一點?
答案1
您需要使用mark repeat
按鍵以頻繁的間隔重複標記。mark phase
將告訴標記應該從哪一點開始。例如,
make repeat = r,
mark phase = p
將首先將標記放置在p
第一個點,然後放置在p+r
第一個點,然後放置在p+2r
第一個點,等等。
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
\begin{axis}[title=Without \texttt{mark repeat}]
\addplot+[scatter,samples=100] {sin(deg(x))};
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[title= With \texttt{mark repeat=5,mark phase=7}]
\addplot+[scatter,samples=100,
mark repeat=5,mark phase=7]
{sin(deg(x))};
\end{axis}
\end{tikzpicture}
\end{document}