4

I want to include some plots of some functions which approaches certain values. See the screenshot below of tanh.

For clarity I have added some space left and right (see screenshot + MWE below).

However I think this is not correct, because this suggest that e.g. x=4.2 is outside the domain which is not te case.

How is this typically solved? Is this just fine (I am too critical), or is this solved on an another way (add plot domain in legend, different setup)?

Thanks

Screenshot:

enter image description here

MWE:

    \documentclass{standalone}
    \usepackage{pgfplots}
    \begin{document}
    \begin{tikzpicture}[ baseline]
    \begin{axis}[xmin=-5,xmax=5,ymin=-1.5,ymax=1.5,xlabel=$x$,ylabel=$\phi(x)$,enlargelimits=false]
    \addplot[domain=-4:4, black]{(e^\x-e^-\x)/(e^\x+e^-\x)};
  \end{axis}
    \end{tikzpicture}
    \end{document}
1
  • \begin{tikzpicture} \begin{axis}[xlabel=$x$,ylabel=$\phi(x)$] \addplot[domain=-4:4]{(e^\x-e^-\x)/(e^\x+e^-\x)}; \end{axis} \end{tikzpicture} would be enough to type here. Just add the information of your domain to the axis title or in your caption or legend. This really does not matter. Or you add a bit of a dotted curve with greater domain below. As it stands now, it has nothing to do with LaTeX. I will vote as off-topic though.
    – LaRiFaRi
    Sep 14 '15 at 11:40
2

One thing you could do is plot the graph 2 extra times with another domain and linestyle (gray, dashdotted or anything you like) with domains <-4 and >4.

    \addplot[domain=-4:4,  black]{(e^\x-e^-\x)/(e^\x+e^-\x)};
    \addplot[domain=-4:-5, black, dotted]{(e^\x-e^-\x)/(e^\x+e^-\x)};
    \addplot[domain= 4:5,  black, dotted]{(e^\x-e^-\x)/(e^\x+e^-\x)};

Otherwise I would say that it looks fine as it is. You could always specify in your text what the figure illustrates, as long as the values outside the figure are not too relevant with your text.

1

If you increase the number of samples, you just need to print two curves (see Robin's answer)

% arara: pdflatex

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}

\begin{document}
\begin{tikzpicture}
    \begin{axis}[xlabel=$x$,ylabel=$\phi(x)$]
        \addplot[domain=-4.5:4.5,dotted,samples=120]{(e^\x-e^-\x)/(e^\x+e^-\x)};
        \addplot[domain=-4:4,samples=120]{(e^\x-e^-\x)/(e^\x+e^-\x)};
    \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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