线上的标记太多了,我怎么才能只绘制几个标记呢?
\documentclass[tikz]{standalone}
\RequirePackage{pgfplots}
\begin{document}
% This file was created by matlab2tikz.
%
%The latest updates can be retrieved from
% http://www.mathworks.com/matlabcentral/fileexchange/22022-matlab2tikz-matlab2tikz
%where you can also make suggestions and rate matlab2tikz.
%
\definecolor{mycolor1}{rgb}{0.58824,0.58824,0.58824}%
\definecolor{mycolor2}{rgb}{0.89412,0.10196,0.10980}%
\definecolor{mycolor3}{rgb}{0.21569,0.49412,0.72157}%
\definecolor{mycolor4}{rgb}{0.30196,0.68627,0.29020}%
\definecolor{mycolor5}{rgb}{1.00000,0.49804,0.00000}%
%
\begin{tikzpicture}
\begin{axis}[%
width=4.521in,
height=3.539in,
at={(0.758in,0.508in)},
scale only axis,
xmin=0,
xmax=3000,
xtick={ 0, 500, 1000, 1500, 2000, 2500, 3000},
xlabel style={font=\color{white!15!black}},
xlabel={X},
ymin=0,
ymax=1,
ylabel style={font=\color{white!15!black}},
ylabel={Y},
axis background/.style={fill=white},
axis x line*=bottom,
axis y line*=left,
xmajorgrids,
ymajorgrids,
legend style={at={(0.03,0.03)}, anchor=south west, legend cell align=left, align=left, draw=white!15!black}
]
\addplot [color=mycolor4, dashed, line width=2.0pt, mark=square, mark options={solid, mycolor4}]
table[row sep=crcr]{%
50 0.9834264\\
100 0.974296\\
150 0.9648184\\
200 0.9529258\\
250 0.9410852\\
300 0.9304922\\
350 0.920181\\
400 0.9098856\\
450 0.9005352\\
500 0.8908822\\
550 0.8804412\\
600 0.867324\\
650 0.8567086\\
700 0.8448816\\
750 0.8282384\\
800 0.8195136\\
850 0.8067574\\
900 0.7918128\\
950 0.7785728\\
1000 0.7620058\\
1050 0.7464702\\
1100 0.7249504\\
1150 0.7063224\\
1200 0.686981\\
1250 0.663326\\
1300 0.6409518\\
1350 0.6151574\\
1400 0.5793994\\
1450 0.5536608\\
1500 0.5244878\\
1550 0.4909266\\
1600 0.452572\\
1650 0.419305\\
1700 0.3855892\\
1750 0.3481886\\
1800 0.3107104\\
1850 0.2804826\\
1900 0.248753\\
1950 0.223371\\
2000 0.1922176\\
2050 0.171771\\
2100 0.1519022\\
2150 0.13144\\
2200 0.113525\\
2250 0.0949822\\
2300 0.0790246\\
2350 0.0656442\\
2400 0.0598496\\
2450 0.0489776\\
2500 0.0411896\\
2550 0.03396\\
2600 0.0285898\\
2650 0.0242706\\
2700 0.019216\\
2750 0.0153486\\
2800 0.0130666\\
2850 0.0091866\\
2900 0.0079618\\
};
\addlegendentry{my line}
\end{axis}
\end{tikzpicture}%
\end{document}
答案1
编辑:mark repeat
第 4.7 节标记、线条样式、(背景)颜色和色彩图
旧答案
在 pgfplots 文档中的 4.22 节“跳过或更改坐标 – 过滤器”中
有x filter/.expression
或x filter/.code
例如x filter/.expression={mod(x,100)==0 ? nan : x},
\documentclass[tikz,boreder=1cm]{standalone}
\RequirePackage{pgfplots}
\pgfplotsset{compat=1.18}%<< this line
\begin{document}
% This file was created by matlab2tikz.
%
%The latest updates can be retrieved from
% http://www.mathworks.com/matlabcentral/fileexchange/22022-matlab2tikz-matlab2tikz
%where you can also make suggestions and rate matlab2tikz.
%
\definecolor{mycolor1}{rgb}{0.58824,0.58824,0.58824}%
\definecolor{mycolor2}{rgb}{0.89412,0.10196,0.10980}%
\definecolor{mycolor3}{rgb}{0.21569,0.49412,0.72157}%
\definecolor{mycolor4}{rgb}{0.30196,0.68627,0.29020}%
\definecolor{mycolor5}{rgb}{1.00000,0.49804,0.00000}%
%
\begin{tikzpicture}
\begin{axis}[%
width=4.521in,
height=3.539in,
at={(0.758in,0.508in)},
scale only axis,
xmin=0,
xmax=3000,
xtick={ 0, 500, 1000, 1500, 2000, 2500, 3000},
xlabel style={font=\color{white!15!black}},
xlabel={X},
ymin=0,
ymax=1,
ylabel style={font=\color{white!15!black}},
ylabel={Y},
axis background/.style={fill=white},
axis x line*=bottom,
axis y line*=left,
xmajorgrids,
ymajorgrids,
legend style={at={(0.03,0.03)}, anchor=south west, legend cell align=left, align=left, draw=white!15!black}
]
\addplot [
% x filter/.expression={mod(x,100)==0 ? nan : x},%<< this line
color=mycolor4,
dashed,
line width=2.0pt,
mark=square,
mark options={solid, mycolor4},
mark repeat={10},%<< this line
]
table[row sep=crcr]{%
50 0.9834264\\
100 0.974296\\
150 0.9648184\\
200 0.9529258\\
250 0.9410852\\
300 0.9304922\\
350 0.920181\\
400 0.9098856\\
450 0.9005352\\
500 0.8908822\\
550 0.8804412\\
600 0.867324\\
650 0.8567086\\
700 0.8448816\\
750 0.8282384\\
800 0.8195136\\
850 0.8067574\\
900 0.7918128\\
950 0.7785728\\
1000 0.7620058\\
1050 0.7464702\\
1100 0.7249504\\
1150 0.7063224\\
1200 0.686981\\
1250 0.663326\\
1300 0.6409518\\
1350 0.6151574\\
1400 0.5793994\\
1450 0.5536608\\
1500 0.5244878\\
1550 0.4909266\\
1600 0.452572\\
1650 0.419305\\
1700 0.3855892\\
1750 0.3481886\\
1800 0.3107104\\
1850 0.2804826\\
1900 0.248753\\
1950 0.223371\\
2000 0.1922176\\
2050 0.171771\\
2100 0.1519022\\
2150 0.13144\\
2200 0.113525\\
2250 0.0949822\\
2300 0.0790246\\
2350 0.0656442\\
2400 0.0598496\\
2450 0.0489776\\
2500 0.0411896\\
2550 0.03396\\
2600 0.0285898\\
2650 0.0242706\\
2700 0.019216\\
2750 0.0153486\\
2800 0.0130666\\
2850 0.0091866\\
2900 0.0079618\\
};
\addlegendentry{my line}
\end{axis}
\end{tikzpicture}%
\end{document}