1

I am trying to create a xbar diagram with pgfplots package. But the bars are not propotional to each other. Here is a minimal example:

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\begin{document}
    \begin{tikzpicture}
    \begin{axis}[
    y axis line style = { opacity = 0 },
    axis x line       = none,
    tickwidth         = 0pt,
    ytick={1,2},
    yticklabels={1,2},
    xbar,
    nodes near coords, 
    nodes near coords align={horizontal}
    ]
    \addplot coordinates {
        (1000,2)
        (500,1)
    };
    \end{axis}
    \end{tikzpicture}
\end{document}

enter image description here

If I change the value of 1 to 1,000 they are the same size. But why is the bar not half the size of 2 if the value is half the size of 2?

2

You should add xmin=0:

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\begin{document}
    \begin{tikzpicture}
    \begin{axis}[
    y axis line style = { opacity = 0 },
    axis x line       = none,
    tickwidth         = 0pt,
    ytick={1,2},
    yticklabels={1,2},
    xbar,
    nodes near coords, 
    nodes near coords align={horizontal},
    xmin = 0
    ]
    \addplot coordinates {
        (1000,2)
        (500,1)
    };
    \end{axis}
    \end{tikzpicture}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.