1

I am trying to display on horizontal bar plot numeric data however when i try to add string labels instead of numbers on y axis it do not work - What am I doing wrong?

code

\documentclass{minimal}
\usepackage{pgfplots}

\begin{document}

        \begin{tikzpicture}
            \tikzstyle{every node}=[font=\large]
            \begin{axis} [xbar = .05cm,
                    bar width = 12pt,
                    xmin = 0, 
                    xmax = 4, 
                    enlarge y limits = {abs = .8},
                    enlarge x limits = {value = .25, upper},
                    title={Execution time log scale}{\large},
                    xlabel = {time[ms]},
                    ]
                \addplot coordinates {(3.66,0) (3.66,1) (3.66,2) (2.55,3)};
                \addplot coordinates {(1.35,0) (1.51,1) (1.37,2) (1.35,3)};
                 \legend{reference,author}
            \end{axis}
             
        \end{tikzpicture}
\end{document}

Plot looks ok but on y axis has numbers instead of titles

now I try to modify code to use symbolic names

\documentclass{minimal}
\usepackage{pgfplots}

\begin{document}
            \tikzstyle{every node}=[font=\large]
            \begin{axis} [xbar = .05cm,
                    bar width = 12pt,
                    xmin = 0, 
                    xmax = 4, 
                    enlarge y limits = {abs = .8},
                    enlarge x limits = {value = .25, upper},
                    title={Execution time log scale}{\large},
                    xlabel = {time[ms]},
                    ymbolic y coords = {HD vs Monai,robust HD,mean HD,HD vs Oliviera}
                    ]
                \addplot coordinates {(3.66,HD vs Monai),(3.66,robust HD) (3.66,mean HD) (2.55,HD vs Oliviera)};
                \addplot coordinates {(1.35,HD vs Monai) (1.51,robust HD) (1.37,mean HD) (1.35,HD vs Oliviera)};
                 \legend{reference,author}
            \end{axis}
             
        \end{tikzpicture}
\end{document}

This is what I get

enter image description here

1

1 Answer 1

1

There is a typo ymbolic y coords should be symbolic y coords. You have extra comma in here (3.66,HD vs Monai),(3.66,robust HD) should be (3.66,HD vs Monai) (3.66,robust HD). And you cannot use enlarge y limits = {abs = .8} for symbolic y coords. You must give a unit for the number. e.g. enlarge y limits = {abs = .8cm}

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}
\begin{tikzpicture}
\tikzstyle{every node}=[font=\large]
\begin{axis} [xbar,
    bar width = 12pt,
    xmin = 0, 
    xmax = 4, 
    enlarge y limits={abs=0.8cm},
    enlarge x limits = {value = .25, upper},
    title={Execution time log scale}{\large},
    xlabel = {time[ms]},
    symbolic y coords = {HD vs Monai,robust HD,mean HD,HD vs Oliviera},
    ]
    \addplot coordinates{
    (3.66,HD vs Monai) (3.66,robust HD) (3.66,mean HD) (2.55,HD vs Oliviera)};
    \addplot coordinates{
    (1.35,HD vs Monai) (1.51,robust HD) (1.37,mean HD) (1.35,HD vs Oliviera)};
    \legend{reference,author}
\end{axis}
             
\end{tikzpicture}

\end{document}

enter image description here

You must log in to answer this question.

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