水平条形图 pgfplot

水平条形图 pgfplot

我想使用 TiKz pgfplots 或使用下表制作两个图表。但出现错误

! 包 pgfplots 错误:抱歉,输入坐标“血流感染(B SI)”尚未定义为“符号坐标={血流感染 (BSI)、手术部位感染 (SSI)、呼吸机相关性肺炎 (VAP)、泌尿道感染 (UTI)、其他}... 可能是拼写错误?

我没有正确定义中的名称吗y coords

**Type of infection Mean cost   Stdev   St dev Min  Stdev Max   %**
Bloodstream Infection (BSI) 36441   37078   2883    207256  14
Surgical site infections (SSI)  25546   39875   1783    134602  17
Ventilator-associated pneumonia (VAP)   9969    2920    7904    12034   14
Urinary tract infection (UTI)   1006    503 650 1361    33
Others  1000    1000    800 5000    22

感染类型与成本 感染类型 vs %

 \documentclass{article}
\usepackage{tikz} 
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document}

 \begin{tikzpicture}
\begin{axis}[ 
xbar, xmin=0,
xlabel={Percentage \%},
symbolic y coords={{Bloodstream Infection (BSI)},{Surgical site infections (SSI)},{Ventilator-associated pneumonia (VAP)},{Urinary tract infection (UTI)},{Others}},
ytick=data,
nodes near coords, nodes near coords align={horizontal},
ytick=data,
]
\addplot coordinates {(14,{Bloodstream Infection (BSI)}) (17,{Surgical site infections (SSI)}) (14,{Ventilator-associated pneumonia (VAP)}) (33,{Urinary tract infection (UTI)})(22, {Others})};
\end{axis}
\end{tikzpicture} %width=6cm,height=7.59cm

\end{document}

答案1

当使用符号坐标时,给出的模式应与坐标中给出的模式完全匹配。因此,应删除symbolic <x or y> coords之前的空格。{Others}

此外,如果符号坐标本身有括号或逗号等字符,会在坐标解析过程中引起混淆,(<some text with ( or comma> , <some text with ( or comma>)则应将它们放在括号对中,以便解析器将它们作为一组字符而不是找到逗号并开始解析下一个坐标。

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}

\begin{document}
\begin{tikzpicture}
\begin{axis}[ 
xbar, xmin=0,
xlabel={Percentage \%},
symbolic y coords={%
    {Bloodstream Infection (BSI)},
    {Surgical site infections (SSI)},
    {Ventilator-associated pneumonia (VAP)},
    {Urinary tract infection (UTI)},
    Others},
ytick=data,
nodes near coords, 
nodes near coords align={horizontal},
ytick=data,
]
\addplot coordinates {
    (14,{Bloodstream Infection (BSI)}) 
    (17,{Surgical site infections (SSI)}) 
    (14,{Ventilator-associated pneumonia (VAP)}) 
    (33,{Urinary tract infection (UTI)})
    (22,Others)};
\end{axis}
\end{tikzpicture} %width=6cm,height=7.59cm
\end{document}

在此处输入图片描述

相关内容