10

I've the following pgfplot:

\begin{center}
    \begin{tikzpicture}
        \begin{axis}[
            xlabel = Number of threads (\#),
            ylabel = Task completion time (seconds),
            xtick = {0, 4, 8, 12, 16},
            ytick = {0, 5000, 10000, 15000, 20000, 25000},
            % ymax = 6,
            % ymin = 0,
            x = 2.5cm/4,
            legend pos = north east]

        \addplot[smooth, thick, color = red, mark = *]
            plot coordinates {
                (1, 23849)
                (2, 11920)
                (3, 7955.8)
                (4, 5971.6)
                (5, 4786.2)
                (6, 3991.8)
                (7, 3440.4)
                (8, 3018.4)
                (9, 3656.2)
                (10, 3411.2)
                (11, 3299)
                (12, 3233)
                (13, 3165.8)
                (14, 3168.2)
                (15, 3099.4)
                (16, 3050.4)
            };
        \addlegendentry{CoinFlip --- \texttt{Running Time}} 
        \end{axis}
    \end{tikzpicture}
\end{center}

enter image description here

I wish to add a label like: \label{graph:running_time_1} and then somehow refer to it like in images and tables.

Also, I would like to add captions for this.

I've been somehow unsuccessful in finding the right way of doing this. I don't wish to create images and then add captions or labels; I just want pgfplots to handle all of that.

  • You can put that code in \begin{figure}..\end{figure} and use \caption and \label as usual. You don't have to use an image and \includegraphics to use figure – David Carlisle Mar 7 '13 at 22:58
  • Thanks @DavidCarlisle. I did what you said. I added: \label{graph:running_time_1} just before \end{figure}. But somehow when I refer to it using: \ref{graph:running_time_1}, it shows nothing. And I'm running the typesetter with more than 2 runs. – p0lAris Mar 7 '13 at 23:02
  • Okay it works! :) – p0lAris Mar 7 '13 at 23:10
12

You can put that code in \begin{figure}..\end{figure} and use \caption and \label as usual. You don't have to use an image and \includegraphics to use figure

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.