![节点仅在绘图边缘附近部分渲染](https://linux22.com/image/266158/%E8%8A%82%E7%82%B9%E4%BB%85%E5%9C%A8%E7%BB%98%E5%9B%BE%E8%BE%B9%E7%BC%98%E9%99%84%E8%BF%91%E9%83%A8%E5%88%86%E6%B8%B2%E6%9F%93.png)
我正在尝试绘制一个相对简单的数轴图表,当其中一个节点太靠近图的边缘时,它会被切断。
代码:
\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}