2

It is written in documentclass beamer. Additionally, the code \captionof{}{} doesn't work either.

    \begin{frame}{Motivation}
    \begin{center}

    \begin{tikzpicture}[scale=0.6]

    \begin{axis}[%
    width=4.521in,
    height=3.566in,
    at={(0.758in,0.481in)},
    scale only axis,
    xmin=-0,
    xmax=10,
    ymin=0,
    ymax=10,
    axis background/.style={fill=white},
    legend style={at={(0.658,0.788)},anchor=south west,legend cell align=left,align=left,draw=white!15!black}
    ]
    \draw[color=red]    plot (\x,{-ln(\x)})             node[right] {$f(x) =ln(x)$};

    \end{axis}
    \end{tikzpicture}


    Caption
        \end{center}
   \end{frame}
3

Well, MarcoG beat me for few minutes ... but in my suggestion I omit all surplus parts of code and use figure environment with caption. Also I use usual pgfplots yntax for such diagrams:

Edit: In your MWE the domain of function is not defined, so pgfplots consider default domain. Consequently, the function was draw only on this domain regardles that xmax is bigger) In the first version of answer, I follow your code (to much), now I add domain domain=0:8 (8 I select that the label of function is still inside of graph) and obtain the result below:

documentclass{beamer}
\usepackage{pgfplots}

    \begin{document}
\begin{frame}{Motivation}

\begin{figure}
    \centering
\begin{tikzpicture}[scale=0.6]
\begin{axis}[%
width=4.521in,
height=3.566in,
scale only axis,
xmin=-0,
xmax=10,
axis background/.style={fill=white},
legend style={at={(0.658,0.788)},anchor=south west,
              legend cell align=left, align=left, 
              draw=white!15!black}
]
\addplot+[domain=0:8] {-ln(\x)}  node[right] {$f(x)=ln(x)$};
\legend{f(x)};
\end{axis}
\end{tikzpicture}
\caption{Caption}
    \end{figure}
\end{frame}
   \end{document}

enter image description here

In case that you like to present more function on graph, just add addplot[...] { ...} into code. For example as you ask in comment:

 \addplot+[domain=0.1:8] {1/(4*\x)} node[right] {$y(x)=1/(4x)$};

and also add this function into legend:

 \legend{f(x),y(x)};

In this case the graph is:

enter image description here

Addendum: in comments are may subquestions. I try to add answers in comment too, but for completnes let mi sumirised it in MWE and picrure with graph (with this would be easy check, if I correctly undersatand them :-)

\documentclass{beamer}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
    \begin{document}
\begin{frame}{Motivation}

\begin{figure}
    \centering
\begin{tikzpicture}[scale=0.6]
\begin{axis}[%
width=4.521in,
height=3.566in,
scale only axis,
xmin= 0, xmax=10,
ymin=-2.5, ymax=2.5,
ticks=none,% no numbers
axis background/.style={fill=white},
legend style={at={(0.658,0.788)},anchor=south west,
              legend cell align=left, align=left, 
              draw=white!15!black},
]
\addplot+[domain=0.0:10] {-ln(\x)}  node[right] {$f(x)=ln(x)$};
\addplot+[domain=0.1:10] {1/(4*\x)} node[right] {$y(x)=\frac{1}{4x}$};
\legend{f(x),y(x)};
\draw[dashed] (2,-2.5) -- (2,3);% regions x<=2
\draw[dashed] (0,0) -- (10,0);  % region y<=0
\end{axis}
\end{tikzpicture}
\caption{Caption}
    \end{figure}
\end{frame}
   \end{document}

enter image description here

6
  • What if I change this the function to y=1/4x? And why does the function always end at x=5? – Kistar Sep 24 '16 at 13:59
  • Because in your (and also mine) MWE is not determined domain of function. So it is used default value, which seems to be 5. See edit of my answer. – Zarko Sep 24 '16 at 16:02
  • And further: how can I remove the numbers on axes and the points (rectangle) on function curves? – Kistar Sep 24 '16 at 18:49
  • How to indicate a region, for example, x\geq2 &&y\geq0? – Kistar Sep 24 '16 at 18:50
  • 1
    Huh, to many sub-questions for an answer. The best advise is: start to read pgplots manual :-). (i): ticks=none, (ii) this question is not clear, maybe \draw[dashed] (2,-2.5) -- (2,3) (0,0) -- (10,0); would give what you after. However, for this lines you need add to preamble \pgfplotsset{compat=1.14} – Zarko Sep 24 '16 at 19:26
3

You could use the following code. I changed the domain (commented the ymin and ymax entries) since the function is mainly negative. Moreover, with pgfplots you should use the \addplot command instead of \draw. See if the following is what you where looking for.

\documentclass{beamer}

\usepackage{pgfplots}
\usetikzlibrary{calc}

\begin{document} 

\begin{frame}{Motivation}
\begin{center}
\begin{tikzpicture}[scale=0.6]

    \begin{axis}[%
    width=4.521in,
    height=3.566in,
    at={(0.758in,0.481in)},
    scale only axis,
    xmin=0,
    xmax=10,
    %ymin=0,
    %ymax=10,
    axis background/.style={fill=white},
    legend style={at={(0.658,0.788)},anchor=south west,legend cell align=left,align=left,draw=white!15!black}
    ]
    \addplot[color=red] (\x,{-ln(\x)}) node[right] {$f(x) =-ln(x)$};
    \end{axis}
    \end{tikzpicture}

    Caption
   \end{center}
   \end{frame}

\end{document}

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.