I have the following code:

\documentclass[11pt,twoside,a4paper]{article}
\usepackage{pgfplots}
\begin{document}
\begin{figure}
    \small\begin{tikzpicture}
        \begin{axis}[
            xmajorticks=false, xbar, y=-0.4cm, bar width=0.3cm,axis lines=left,
            x axis line style={draw=none},
            symbolic y coords={A,B,C,D,E,F,G},
            ytick=data, nodes near coords, nodes near coords align={horizontal},
          ]
            \addplot coordinates {
                (1000,A)
                (800,B)
                (500,C)
                (100,D)
                (600,E)
                (150,F)
                (300,G)
            };
        \end{axis}
    \end{tikzpicture}
\end{figure}
\end{document}

which generates a horizontal bar chart. However, Bar A and Bar G are displayed at only half width. How do I make the bar widths the same?

EDIT:

The following is the output:

enter image description here

up vote 6 down vote accepted

enlargelimits option can solve the problem.

enter image description here

\documentclass[11pt,twoside,a4paper]{article}
\usepackage{pgfplots}
\begin{document}
\begin{figure}
\small\begin{tikzpicture}
\begin{axis}[
xmajorticks=false, xbar, y=-0.4cm, bar width=0.3cm,axis lines=left,enlargelimits=0.1,
x axis line style={draw=none},
symbolic y coords={A,B,C,D,E,F,G},
ytick=data, nodes near coords, nodes near coords align={horizontal},
]

\addplot coordinates{
(1000,A)
(800,B)
(500,C)
(100,D)
(600,E)                                                                                   
(150,F)                                                               
(300,G)
};                                                                                                                       
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}

Alternate way

Another way is to set ymin and ymax.

enter image description here

\documentclass[11pt,twoside,a4paper]{article}
\usepackage{pgfplots}
\begin{document}
\begin{figure}
\small\begin{tikzpicture}
\begin{axis}[
xmajorticks=false, xbar, y=-0.4cm, bar width=0.3cm,axis lines=left,
ymin={[normalized]-1}, ymax={[normalized]7},
x axis line style={draw=none},
symbolic y coords={A,B,C,D,E,F,G},
ytick=data, nodes near coords, nodes near coords align={horizontal},
]

\addplot coordinates{
(1000,A)
(800,B)
(500,C)
(100,D)
(600,E)                                                                                                                   
(150,F)                                                                                                                           
(300,G)
};                                                                                                                       
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
  • 1
    Thanks @nidhin. – qzx Nov 19 at 10:44

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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