Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
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. –  flippex17 Mar 7 '13 at 23:02
    
Okay it works! :) –  flippex17 Mar 7 '13 at 23:10
add comment

1 Answer

up vote 4 down vote accepted

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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