条形图的顶部和底部不显示

条形图的顶部和底部不显示

我的条形图的顶部和底部条形图在我的文档中消失了。有人能告诉我我的代码哪里出错了吗?另外,我如何输入 % 符号作为每个条形图的单位?最后一个问题:如何添加标题和 x 轴?抱歉,我对这些都很陌生。有点挣扎

\documentclass[a4paper]{article}
\usepackage{amsmath}
\usepackage[T1]{fontenc}
\usepackage{lmodern,textcomp}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}

\begin{document}
\begin{center}
\begin{minipage}{\linewidth}
\centering
\begin{tikzpicture}
  \begin{axis}[
      xbar,
      y axis line style = {draw=none},
      axis x line       = none,
      tickwidth         = 0pt,
      enlarge y limits  = 0.02,
      enlarge x limits  = 0.05,
      symbolic y coords = {Cosmesis, Psychological Stress, Scarring Problems, Wound Problems, All patients with Morbidity, Total Study Cohort},
      ytick=data,
      nodes near coords,
      legend style={anchor=south},
      reverse legend
  ]
    \addplot[fill=white] coordinates { 

      (100,Cosmesis)
      (92,Psychological Stress)
      (87,Scarring Problems)
      (92,Wound Problems)
      (76,All patients with Morbidity)
      (57,Total Study Cohort)
    };
    \addplot[fill=black!10]coordinates {

      (0,Cosmesis)
      (8 ,Psychological Stress)
      (13 ,Scarring Problems)
      (3,Wound Problems)
      (24,All patients with Morbidity)
      (43,Total Study Cohort)
    };
    \legend{Female, Male}
  \end{axis}
\end{tikzpicture}

\end{minipage}
\end{center}
\end{document}

答案1

可能的答案(注释掉不需要的包并稍微简化代码):

\documentclass[a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
%\usepackage{lmodern,textcomp}
%\usepackage{amsmath}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}

\begin{document}

\begin{center}
\begin{tikzpicture}
  \begin{axis}[
      xbar,
      y axis line style = {draw=none},
      tickwidth         = 0pt,
      symbolic y coords = {Cosmesis, Psychological Stress, Scarring Problems, Wound Problems, All patients with Morbidity, Total Study Cohort},
      ytick             = data,
      xticklabel        = {\pgfmathprintnumber\tick\%},
      nodes near coords = {\pgfmathprintnumber\pgfplotspointmeta\%},
      reverse legend
  ]
    \addplot[fill=white] coordinates { 
      (100,Cosmesis)
      (92,Psychological Stress)
      (87,Scarring Problems)
      (92,Wound Problems)
      (76,All patients with Morbidity)
      (57,Total Study Cohort)
    };
    \addplot[fill=black!10] coordinates {
      (0,Cosmesis)
      (8,Psychological Stress)
      (13,Scarring Problems)
      (3,Wound Problems)
      (24,All patients with Morbidity)
      (43,Total Study Cohort)
    };
    \legend{Female, Male}
  \end{axis}
\end{tikzpicture}
Figure 1: I am a caption.
\end{center}

\end{document}

在此处输入图片描述

相关内容