節點僅在繪圖邊緣附近部分渲染

節點僅在繪圖邊緣附近部分渲染

我正在嘗試繪製一個相對簡單的數軸圖表,當其中一個節點太靠近圖的邊緣時,它會被切斷。

代碼:

\documentclass{article}

\usepackage{natbib}
\usepackage{graphicx}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
  width=\columnwidth,
  axis y line=none,
  axis lines=left,
  axis line style={-},
  xmin=0,
  xmax=1,
  ymin=0,
  ymax=1,
  xlabel=$\mu$,
  scatter/classes={o={mark=*}},
  restrict y to domain=0:1,
  xtick={0,1}
]
\draw[ultra thin] (axis cs:0, 0) -- (axis cs:0,.05);
\draw[ultra thin] (axis cs:.4, 0) -- (axis cs:.4,.05);
\node[coordinate,label=above:{$B$}] at (axis cs:0.0,0.05) {};
\node[coordinate,label=above:{$A$}] at (axis cs:0.4,0.05) {};
\node[coordinate,label=above:{$b$}] at (axis cs:0.2,0.02) {};
\node[coordinate,label=above:{$a$}] at (axis cs:0.7,0.02) {};
\end{axis};
\end{tikzpicture}
\end{document}

結果:

部分渲染的節點標籤

如何讓 B 完全渲染?

答案1

預設情況下,axis邊界框內的任何路徑都會被剪切,這就是剪切 B 的原因clip=false

裁剪將在章節中討論4.19.2 裁剪手冊(適用於 1.8 版pgfplots,日期為 2013 年 3 月 7 日)。

正如 Jake 在評論中提到的:在 1.8 版本中引入了pgfplotskey clip mode=individual,它將剪輯情節線,但不會剪輯普通節點。

\documentclass{article}

\usepackage{natbib}
\usepackage{graphicx}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
  width=\columnwidth,
  axis y line=none,
  axis lines=left,
  axis line style={-},
  xmin=0,
  xmax=1,
  ymin=0,
  ymax=1,
  xlabel=$\mu$,
  scatter/classes={o={mark=*}},
  restrict y to domain=0:1,
  xtick={0,1},
  clip=false    % <-- new addition
  % clip mode=individual  % alternative
]
\draw[ultra thin] (axis cs:0, 0) -- (axis cs:0,.05);
\draw[ultra thin] (axis cs:.4, 0) -- (axis cs:.4,.05);
\node[coordinate,label=above:{$B$}] at (axis cs:0.0,0.05) {};
\node[coordinate,label=above:{$A$}] at (axis cs:0.4,0.05) {};
\node[coordinate,label=above:{$b$}] at (axis cs:0.2,0.02) {};
\node[coordinate,label=above:{$a$}] at (axis cs:0.7,0.02) {};
\end{axis};
\end{tikzpicture}
\end{document}

相關內容