给出下图:
\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}
然后像这样引用标签:
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}.
这是怎么回事?
答案1
遗憾的是,您没有提供(完整)最小工作示例(MWE),所以当我添加缺失的东西时,一切都正常。
% 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}