在此 MWE 中,我需要透過軸剪掉黃色方塊標記,同時保持紅色菱形標記完好無損。
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin=0, xmax=1,
ymin=0, ymax=1,
domain=0:1,
every axis plot post/.append style={
line width=2pt,
}
]
\addplot [ mark=square*, mark size=4pt,
mark options={fill=yellow, line width = 0.5pt}, samples = 3 ] {x};
\addplot [ only marks, mark=diamond*, mark size=5pt,
mark options={fill=red, line width = 0.5pt}, samples = 2 ] {x};
\end{axis}
\end{tikzpicture}
\end{document}
附錄
clip marker paths
使用圖層時該選項不起作用。這種情況該如何解決呢?
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest,
layers/my layer set/.define layer set={bg,main,fg}{},
set layers=my layer set,
mark layer=like plot}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin=0, xmax=1,
ymin=0, ymax=1,
domain=0:1,
every axis plot post/.append style={
line width=2pt,
}
]
\addplot [ mark=square*, mark size=4pt,
mark options={fill=yellow, line width = 0.5pt}, samples = 3, clip marker paths, on layer = bg ] {x};
\addplot [ only marks, mark=diamond*, mark size=5pt,
mark options={fill=red, line width = 0.5pt}, samples = 2, on layer = fg ] {x};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
將選項新增clip marker paths
至繪圖中,進行黃色標記。
編輯:正如所指出的,這在使用圖層時不起作用。然而,使用clip mode=individual
它似乎是有效的。
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest,
layers/my layer set/.define layer set={bg,main,fg}{},
set layers=my layer set,
mark layer=like plot}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin=0, xmax=1,
ymin=0, ymax=1,
domain=0:1,
every axis plot post/.append style={
line width=2pt,
}
]
\addplot [ mark=square*, mark size=4pt,
mark options={fill=yellow, line width = 0.5pt}, samples = 3, on layer = bg,
clip mode=individual % <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
] {x};
\addplot [ only marks, mark=diamond*, mark size=5pt,
mark options={fill=red, line width = 0.5pt}, samples = 2, on layer = fg ] {x};
\end{axis}
\end{tikzpicture}
\end{document}