Take the 2-minute tour ×
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.

Question

I would like to add a label to my graph, on the right of it or at any other place, for instance somewhere above my graph.

Is it possible?

I want to use the option clip=true, because of the graph of tan(x) (see the picture below)

Code and picture

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis x line = middle, 
axis y line = middle, 
domain=-2:2,
xmin = -2, 
xmax = 2,  
ymin=-10,
ymax=10,
grid = major, 
clip = false]
\addplot[color=orange, samples=100, smooth, ultra thick] {tan(deg(x))}  node[right] {$\tan$};
\end{axis}
\end{tikzpicture}

\end{document}

enter image description here

If I remove the options ymin=..., ymax=..., the output is fine, but I would like, if possible, to set the values of ymin and ymax.

share|improve this question
add comment

1 Answer 1

up vote 4 down vote accepted

You can set clip mode=individual to clip only the plot lines. However, this also clips nodes added at the end of the plot like in your code, as it is part of the same path. As a workaround you could add an empty, named node at the end of the plot, and place a new node at this location.

enter image description here

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    axis lines = middle,  
    domain=-2:2,
    xmin = -2, 
    xmax = 2,  
    ymin=-10,
    ymax=10,
    grid = major, 
    clip = true,
    clip mode=individual]
\addplot[color=orange, samples=100, smooth, ultra thick] {tan(deg(x))}  node (endofplot) {};
\node [right,orange] at (endofplot) {$\tan(x)$};
\end{axis}
\end{tikzpicture}

\end{document}
share|improve this answer
    
Great! Thanks a lot for your help! As you might have guessed, I am writing a command to draw automatically functions on a graph! –  Colas Apr 7 at 13:04
add comment

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.