绘制条形图时出错

绘制条形图时出错

这是我粗略地尝试从复制的示例创建图表。我想在 Yy 轴上绘制疾病,在 x 轴上绘制 QoL 分数。这导致了错误。有人能指出问题吗?

\documentclass[tikz]{standalone}

\usepackage{pgfplots}

\begin{document}

\pgfplotstableread[row sep=\\,col sep=&]{
    Disease &    Score                                      \\
    Untreated HT&  108  \\
    Normal man &   105\\
    Normal woman & 104\\
    CHF (mild) & 95  \\
    Angina pectoris & 88 \\
    Untreated DU   & 83 \\
  Untreated GER  &  82 \\
  Psychiatric disease & 62 \\ 
      }\mydata

\begin{tikzpicture}
    \begin{axis}[
            ybar,
            bar width=.5cm,
            width=\textwidth,
            height=.5\textwidth,
            legend style={at={(0.5,1)},
                anchor=north,legend columns=-1},
            symbolic x coords={60, 65, 70, 75, 80,85, 90, 95, 100, 105, 110},
            xtick=data,
            nodes near coords,
            nodes near coords align={vertical},
            ymin=60 ,ymax=110
            ylabel={},
        ]
        \addplot table[x=score, y=Disease]{\mydata};

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

答案1

这就是你想要的吗?

截屏

我做的主要改变是

xbar,
...
symbolic y coords={Untreated HT, Normal man, 
            Normal woman, CHF (mild), Angina pectoris,Untreated DU, 
            Untreated GER, Psychiatric disease },
ytick=data,

将其制成xbar图表。

% arara: pdflatex
% !arara: indent: {overwrite: yes}
\documentclass[tikz]{standalone}

\usepackage{pgfplots}

\begin{document}

\pgfplotstableread[row sep=\\,col sep=&]{%
    Disease &    Score                                      \\
    Untreated HT&  108  \\
    Normal man &   105\\
    Normal woman & 104\\
    CHF (mild) & 95  \\
    Angina pectoris & 88 \\
    Untreated DU   & 83 \\
    Untreated GER  &  82 \\
    Psychiatric disease & 62 \\ 
    }\mydata

\begin{tikzpicture}
    \begin{axis}[
            xbar,
            bar width=.5cm,
            width=\textwidth,
            height=.5\textwidth,
            legend style={at={(0.5,1)},
                anchor=north,legend columns=-1},
            %symbolic x coords={60, 65, 70, 75, 80,85, 90, 95, 100, 105, 110},
            symbolic y coords={Untreated HT, Normal man, 
                Normal woman, CHF (mild), Angina pectoris,Untreated DU, 
            Untreated GER, Psychiatric disease },
            ytick=data,
            nodes near coords,
            %nodes near coords align={vertical},
            %ymin=60 ,ymax=110,
            %ylabel={},
        ]
        \addplot table[x=Score, y=Disease]{\mydata};

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

相关内容