2

How can I add caption under my function, for example [Fig 1], and how can I refer to that figure?

My Code:

\begin{tikzpicture}
    \begin{axis}[
        xlabel=$x$,
        ylabel=$\mu(x)$
    ]
    % invoke external gnuplot as
    % calculator:
    \addplot[smooth,samples=180,domain=0.0001:20] {1/(1+(1/x))};
    \end{axis}
\end{tikzpicture}
  • \begin{figure}\begin{tikzpicture}...\end{tikzpicture}\caption{Caption}\label{fig:figure}\end{figure}? – cfr Feb 8 '15 at 16:02
  • I tried that and it just disappears when I add the figure tag.. – MrDi Feb 8 '15 at 16:20
  • Then we need a minimal document which shows the problem when compiled. – cfr Feb 9 '15 at 2:53
3

You can put your plot inside figure environment and add the caption as usual.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
  \begin{figure}
    \centering
    \begin{tikzpicture}
    \begin{axis}[
        xlabel=$x$,
        ylabel=$\mu(x)$
    ]
    % invoke external gnuplot as
    % calculator:
    \addplot[smooth,samples=180,domain=0.0001:20] {1/(1+(1/x))};
    \end{axis}
\end{tikzpicture}
  \caption{This is my plot}\label{fig:myplot}
  \end{figure}

  From \ref{fig:myplot} I don't get nothing.
\end{document}

enter image description here

  • the caption appears as "From ?? I don't get nothing" – MrDi Feb 8 '15 at 16:09
  • @user28952: Did you compile the document twice? – Jake Feb 8 '15 at 16:36
  • It works now, but when I add abstract tag and some writing, the figure disappears, but it reappears if I remove the figure tags and just leave the tikzpicture tag without the caption. – MrDi Feb 8 '15 at 16:52
  • ypu then should post a minimal example where the problem occurs. – MaxNoe Feb 8 '15 at 16:56

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.