我正在尝试绘制一个相对简单的数轴图表,当其中一个节点太靠近图的边缘时,它会被切断。
代码:
\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 版本中引入了pgfplots
密钥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}