1

I am tyring to make this value (16.49) bold in the bar graph. I can't seem to find any answer.

\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}
2
  • Welcome to TeX.SX! Please make your code snippet compilable, so that we don't have to guess which packages and document class you are using. There seems to be a mistake in the values for symbolic y coords, since {h} is missing while {g} exists twice. Commented Feb 23, 2023 at 20:00
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Commented Feb 23, 2023 at 20:00

1 Answer 1

1

You could make use of coordinate style/.condition to format a single value differently than the other. I adjusted your original code a bit:

\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}

enter image description here


An easy solution for also making the relevant tick bold, would be to explicitly define the tick labels:

\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}

enter image description here

10
  • Thank you so much!!!! I don't know how to thank you enough. This was driving me crazy for the last few days. lol Also, I have the following error. It doesn't affect the graph, but any thoughts? <inserted text> \par l.336 \end{axis} I've run across a }' that doesn't seem to match anything. For example, \def\a#1{...}' and \a}' would produce this error. If you simply proceed now, the \par' that I've just inserted will cause me to report a runaway argument that might be the root of the problem. But if your }' was spurious, just type 2' and it will. Commented Feb 23, 2023 at 22:23
  • here's the second error. It shows up after I add cite from a to j in both y cords and coords. {pgfstrokecolor}{\@tempswatrue \@citex }\def \reserved@b {\@tempswafalse \ETC. ! Paragraph ended before \XC@definec@lor was complete. <to be read again> \par l.336 \end{axis} I suspect you've forgotten a `}', causing me to apply this control sequence to too much text. How can we recover? My plan is to forget the whole thing and hope for the best. Commented Feb 23, 2023 at 22:26
  • It doesn't affect the plot though. Commented Feb 23, 2023 at 22:26
  • @abcs_of_plots Well, the first error is typically the one you should care about. It says that there is an unmatched } on line 336. You should look for it. It is hard to help you without having your full code. I cannot reproduce this error, since you did not provide a compilable minimal working example (MWE) which you really should do. Also, I think, you should ask a new question about this, if this is not related to the question (which I think is the case here, if the plot is not affected). Commented Feb 23, 2023 at 22:33
  • Agreed. I will mark this as solved. Commented Feb 23, 2023 at 22:41

You must log in to answer this question.

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