0

I want to create a horizontal bar graph using symbolic y labels. However I:

  • want to have the bars next to each other (i.e., no space between)
  • I want some margin below and above the first and last bar for readability
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}

\begin{axis}[ xbar, axis y line=center, axis x line=center, bar width=4pt, bar shift=0pt, y=4pt, nodes near coords, nodes near coords align={horizontal}, symbolic y coords={A,B,C,D,E,F}, ] \addplot[fill=blue] coordinates { (-58,A) (-45,B) (-43,C) };

  \addplot[fill=red] coordinates {
    (19,D)
    (35,E)
    (65,F)
  };
\end{axis}

\end{tikzpicture} \end{document}

Currently it looks like this and any height specifications are changed into width specifications.

enter image description here

Sim
  • 240

1 Answers1

1

Like this?

enter image description here

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document} \begin{tikzpicture} \begin{axis}[ axis x line=left, axis y line=center, enlargelimits={lower, 0.2}, % xbar=11pt, bar shift=0pt,
y=11pt, % nodes near coords, nodes near coords align={horizontal}, nodes near coords style={font=\scriptsize}, % symbolic y coords={A,B,C,D,E,F}, ytick=\empty, ] \addplot[fill=blue] coordinates { (-58,A) (-45,B) (-43,C) }; \addplot[fill=red] coordinates { (19,D) (35,E) (65,F) }; \end{axis} \end{tikzpicture} \end{document}

Zarko
  • 296,517