1

Given the following Graph:

\begin{tikzpicture} 
 \begin{axis}[ybar, xticklabels={{Less Than 100 Bytes}, {100-1000 Bytes}, {1000-10000 Bytes}, {Greater than 10000 Bytes}}, xtick = {2, 4, 6, 8},
         width = 0.45*\textwidth,
         xtick style={draw=none},
         ymajorgrids=true,
         ylabel={Message Count}, 
         xlabel={Message Size}, xticklabel style={rotate=90},bar shift=0pt]

\addplot [draw=blue, pattern color = blue, pattern = north west lines]
                coordinates {(2, 0)}; 
                \label{plot:lessThan100}
\addplot [draw=yellow, pattern color = yellow, pattern = grid]
    coordinates{(4, 0)}; 
    \label{plot:10}
\addplot [draw=green,pattern color = green, pattern = crosshatch]
    coordinates{(6, 1256)}; 
    \label{plot:1000Bar}
\addplot [draw=black,fill = black]
    coordinates{(8, 2260)}; 
    \label{plot:GreaterThan10000}    
\end{axis}
\end{tikzpicture}

And then referencing back the labels like so:

less than 100 bytes~\ref*{plot:lessThan100}, 100-1000 bytes~\ref*{plot:10}, 1000-10000 bytes~\ref*{plot:1000Bar} and greater than 10000 bytes~\ref*{plot:GreaterThan10000}. 

But it renders the second label correctly: Incorrect references.

Whats going wrong with this?

1 Answer 1

1

Unfortunately you didn't provide a (full) minimal working example (MWE), so when I add the missing stuff, everything works perfectly fine.

% used PGFPlots v1.15
\documentclass[border=5pt,varwidth]{standalone}
\usepackage{pgfplots}
    \usetikzlibrary{
        patterns,
    }
    \pgfplotsset{
        compat=1.15,
    }
\begin{document}
less than 100 bytes~\ref{plot:lessThan100}, 100-1000 bytes~\ref{plot:10},
1000-10000 bytes~\ref{plot:1000Bar} and
greater than 10000 bytes~\ref{plot:GreaterThan10000}.

\begin{tikzpicture}
    \begin{axis}[
        ybar,
        xticklabels={
            {Less Than 100 Bytes},
            {100-1000 Bytes},
            {1000-10000 Bytes},
            {Greater than 10000 Bytes}
        },
        xtick = {2, 4, 6, 8},
        width = 0.45*\textwidth,
        xtick style={draw=none},
        ymajorgrids=true,
        ylabel={Message Count},
        xlabel={Message Size},
        xticklabel style={rotate=90},
        bar shift=0pt,
    ]

        \addplot [draw=blue, pattern color = blue, pattern = north west lines]
            coordinates {(2, 0)};
                \label{plot:lessThan100}
        \addplot [draw=yellow, pattern color = yellow, pattern = grid]
            coordinates{(4, 0)};
                \label{plot:10}
        \addplot [draw=green,pattern color = green, pattern = crosshatch]
            coordinates{(6, 1256)};
                \label{plot:1000Bar}
        \addplot [draw=black,fill = black]
            coordinates{(8, 2260)};
                \label{plot:GreaterThan10000}
    \end{axis}
\end{tikzpicture}
\end{document}

image showing the result of above code

2
  • sorry for not including a MWE, I thought the problem was isolated to how I was adding labels to my plots in PGFPlots, it turns out as I was generating the graphs externally it was playing with the references causing this issue. Moving to standalone graphs has fixed my problem.
    – Dean
    Jan 22, 2018 at 21:29
  • Great. If you like my answer and it was helpful, please consider upvoting (by clicking on the arrows next to the score) and/or marking it as the accepted answer (by clicking on the checkmark ✓). Thank you. Jan 22, 2018 at 21:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .