4

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

1 Answer 1

6

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

You must log in to answer this question.

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