我正在尝试在条形图中将这个值 (16.49) 加粗。我似乎找不到任何答案。
\begin{figure}[ht]
\label{fig:table}
\begin{tikzpicture}
\begin{axis}[
%axis line style={draw=none},
major grid style={dotted,black},
width=0.33\textwidth,
height=0.33\textwidth,
xbar, xmin=0, xmax=70,
yticklabel style={align=center},
xlabel={DEF \%},
xlabel style={font=\smaller},
symbolic y coords={%
{a},
{b},
{c},
{d},
{e},
{f},
{g},
{g},
{i},
{j}
},
ytick=data,
nodes near coords={\pgfmathprintnumber[zerofill, fixed, precision=1]{\pgfplotspointmeta}},
every node near coord/.append style={font=\smaller},
nodes near coords align={horizontal},
ytick=data,
]
\addplot [fill=gray!90,draw=black!70]
coordinates {(16.49,{a})
(17.60,{b})
(26.37,{c})
(29.0,{d})
(29.83,{e})
(29.99,{f})
(36.22,{g})
(43.80,{h})
(49.55,{i})
(54.50,{j})
};
\end{axis}
\end{tikzpicture}
\caption{Abcs}
\end{figure}
答案1
您可以使用 来coordinate style/.condition
格式化单个值,使其不同于其他值。我对您的原始代码进行了一些调整:
\documentclass{article}
\usepackage{relsize, pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width=0.5\textwidth,
height=0.5\textwidth,
xbar, xmin=0, xmax=70,
yticklabel style={align=center},
xlabel={Log-Average Miss Rate \%},
xlabel style={font=\smaller},
symbolic y coords={%
{a},
{b},
{c},
{d},
{e},
{f},
{g},
{h},
{i},
{j}
},
ytick=data,
nodes near coords={
\pgfmathprintnumber[zerofill, fixed, precision=1]{\pgfplotspointmeta}
},
coordinate style/.condition={x == 16.49}{font=\smaller\boldmath},
coordinate style/.condition={x != 16.49}{font=\smaller},
]
\addplot [fill=gray!90,draw=black!70]
coordinates {
(16.49,{a})
(17.60,{b})
(26.37,{c})
(29.0,{d})
(29.83,{e})
(29.99,{f})
(36.22,{g})
(43.80,{h})
(49.55,{i})
(54.50,{j})
};
\end{axis}
\end{tikzpicture}
\end{document}
使相关刻度变为粗体的一个简单解决方案是明确定义刻度标签:
\documentclass{article}
\usepackage{relsize, pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width=0.5\textwidth,
height=0.5\textwidth,
xbar, xmin=0, xmax=70,
yticklabel style={align=center},
xlabel={Log-Average Miss Rate \%},
xlabel style={font=\smaller},
symbolic y coords={%
{a},
{b},
{c},
{d},
{e},
{f},
{g},
{h},
{i},
{j}
},
ytick=data,
yticklabels={\textbf{a},b,c,d,e,f,g,h,i,j},
nodes near coords={
\pgfmathprintnumber[zerofill, fixed, precision=1]{\pgfplotspointmeta}
},
coordinate style/.condition={x == 16.49}{font=\smaller\boldmath},
coordinate style/.condition={x != 16.49}{font=\smaller},
]
\addplot [fill=gray!90,draw=black!70]
coordinates {
(16.49,{a})
(17.60,{b})
(26.37,{c})
(29.0,{d})
(29.83,{e})
(29.99,{f})
(36.22,{g})
(43.80,{h})
(49.55,{i})
(54.50,{j})
};
\end{axis}
\end{tikzpicture}
\end{document}