如何让文字与条形图对齐?

如何让文字与条形图对齐?

我有以下 tikzpicture,但是,正如您在下面看到的,它没有正确对齐 - 我做错了什么?

在此处输入图片描述

\documentclass[border=10pt]{standalone} 
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
  \begin{axis}[
    xbar,
    y axis line style = { opacity = 0 },
    axis x line = none,
    tickwidth = 0pt,
    symbolic y coords = {Chat,E-Mail,SMS,Web notification},
    nodes near coords,
  ]
  \addplot coordinates {(68,Web notification)};
  \addplot coordinates {(22,SMS)};
  \addplot coordinates {(50,E-Mail)};
  \addplot coordinates {(52,Chat)};

  \end{axis}
\end{tikzpicture}
\end{document}

答案1

您可能对以下内容更满意:

在此处输入图片描述

\documentclass[border=10pt]{standalone} 
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
  \begin{axis}[
    xbar,
    y axis line style = { opacity = 0 },
    axis x line = none,
    tickwidth = 0pt,
    symbolic y coords = {Chat,E-Mail,SMS,Web notification},
    nodes near coords,
    bar shift=0pt %<--------------- added
  ]
  \addplot coordinates {(68,Web notification) };
  \addplot coordinates {(22,SMS) (50,E-Mail) (52,Chat)};
  \end{axis}
\end{tikzpicture}
\end{document}

相关内容