2

I'm trying to plot the exponential function enter image description here using pgfplots, but no matter what I change, I get only a part of the plot.

Here's the code (the code and the image were made using exp(0.25x) instead of exp(0.25x-5) but I get a similar result in both cases anyway):

\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}

\begin{document}
\hspace{15mm}
\begin{tikzpicture} 
\begin{axis}[xmin=-5,xmax=15,ymin=0,ymax=1,ylabel= $\mathbb{P}(x)$,xlabel=$x$, 
no markers,samples=100,grid=both]
\addplot {1/(1+exp(0.25*x))};
\end{axis}
\end{tikzpicture}
\end{document}

And here's the plot I get:

enter image description here

3

Adding domain=-5:15 solves the issue for both functions:

enter image description here

Notes:

  • I am not sure why pgfplots did not just extract the domain from xmin and xmax.

Code:

\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}

\begin{document}
\hspace{15mm}
\begin{tikzpicture} 
\begin{axis}[xmin=-5,xmax=15,ymin=0,ymax=1,ylabel= $\mathbb{P}(x)$,xlabel=$x$, 
no markers,samples=100,grid=both,domain=-5:15]
\addplot+ [ultra thick] {1/(1+exp(0.25*x))};
\addplot+ [ultra thick] {1/(1+exp(0.25*x-5))};

\end{axis}
\end{tikzpicture}
\end{document}
  • Thanks! That was the problem, I didn't know I had to indicate the domain. Thanks again. – Raul Sep 30 '14 at 1:22

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.