TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to draw a relatively simple chart of a number line, and when one of the nodes is too close to the edge of the plot, it gets cut off.

The code:

\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}

The Result:

Partially rendered node label

How do I get the B to fully render?

share|improve this question
up vote 6 down vote accepted

By default any paths inside the axis bounding box is clipped, this is what cuts the B. To turn off clipping, add clip=false to the axis options.

Clipping is discussed in section 4.19.2 Clipping of the manual (for version 1.8 of pgfplots, dated 2013-03-07).

As mentioned by Jake in a comment: In version 1.8 of pgfplots the key clip mode=individual was introduced, which will clip plot lines, but not normal nodes.

\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}
share|improve this answer
    
How can I avoid clipping a node added to addplot but the plot line should be clipped? – Hotschke Jun 26 '15 at 10:21
    
@Hotschke Did you try what is mentioned in the last paragraph before the code block? – Torbjørn T. Jun 26 '15 at 10:23
    
Yes, I have tried this. – Hotschke Jun 26 '15 at 10:25
    
I mean something like this: \addplot gnuplot{cos(x)} node[pos=0, pin={90:peak}]{}; – Hotschke Jun 26 '15 at 10:28
1  
@Hotschke IIUC, that's a bit different, I would guess the pin is part of the same path as the plot, which would make it a bit harder I think. Why not add a coordinate and pos=0, and add the node afterwards? I.e. \addplot ... coordinate[pos=0] (a); and then \node [pin...] at (a) {}; – Torbjørn T. Jun 26 '15 at 10:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.