使用 addplot 的比较条形图

使用 addplot 的比较条形图

我正在尝试绘制下面的图表。 期望输出

使用 addplot,我成功绘制了下面的内容。 电流输出

我遇到的问题是为一个年龄组绘制两个条形图。这必须涉及降低每个条形图的高度,但不确定如何实现。有人能帮我吗?

谢谢你!

\documentclass[]{article}
\usepackage[margin=0.05in]{geometry}
\usepackage{pgfplots}
\renewcommand{\thesection}{\arabic{section}}
\usepackage{mathtools}
\usepackage{cancel}
\usepackage{pgfplots}
\usepackage{amsmath}
\newtheorem{theorem}{THEOREM}
\newtheorem{proof}{PROOF}
\usepackage{tikz}
\usepackage{amssymb}
\usetikzlibrary{patterns}
\usepackage{fancyhdr}
\usepackage{bigints}
\usepackage{color}
\usepackage{tcolorbox}
\usepackage{color,xcolor}
\usepackage{booktabs,array}
\usepackage{hyperref}
\usepackage{graphicx}
\usetikzlibrary{arrows}
\usepackage{polynom}
\usepackage{wallpaper}
\usepackage{lscape}
\usepackage{pgf-pie}
\usetikzlibrary{shapes.geometric}
\usepgfplotslibrary{fillbetween}
\usepgfplotslibrary{statistics}
\newenvironment{tightcenter}{
\setlength\topsep{0pt}
\setlength\parskip{0pt}
\begin{center}}{\end{center}}
\begin{document}
\text{}\\\\
\\
\begin{tikzpicture}
\begin{axis}[
axis line style={thick,-},
name=like,
scale only axis,
xbar,
xmin=0,
xmax=7.2,
ymin=0.1,
ymax=1.3,
%
grid style={line width=.1pt, draw=black!60},
grid=major,
ymajorgrids=false,
tick label style={font=\Large},
width=8.2cm,
height=4.5cm,
%
xtick={1,2,3,4,5,6,7},
ytick={0.3,0.6,0.9,1.2},
y tick label style={text width=3cm,align=center},
%
axis x line=left,
axis y line=none,
clip=false
]
\addplot[fill=gray,minimum height = 0.06cm] coordinates {
(6.78,0.3)
(6.54,0.6)
(5.92,0.9)
(5.2,1.2)
};
%
\node[xshift=-1.0cm,align=center] at (axis cs:0,1.2) {\Large 15 - 19};
\node[xshift=-1.0cm,align=center] at (axis cs:0,0.9) {\Large 10 - 14};
\node[xshift=-1.0cm,align=center] at (axis cs:0,0.6) {\Large 5 - 9};
\node[xshift=-1.0cm,align=center] at (axis cs:0,0.3) {\Large 0 - 4};
%
\node[below] at (axis cs:-2,0.08) {\Large 0};
\node[below] at (axis cs:+0,0.08) {\Large 0};
%
\end{axis}
\begin{axis}[ 
at={(like.north west)},anchor=north east, xshift=-2.0cm,
scale only axis,
axis line style=thick,
xbar,
xmin=0,
xmax=7.2,
ymin=0.1,
ymax=1.3,
%
grid style={line width=.1pt, draw=black!60},
grid=major,
ymajorgrids=false,
%
tick label style={font=\Large},
xtick={1,2,3,4,5,6,7},
ytick={0.3,0.6,0.9,1.2},
yticklabels={},
width=8.2cm,
height=4.5cm,
x dir=reverse,
axis x line=left,
axis y line=none,
]
\addplot[fill=black] coordinates {
(6.8,0.3)
(6.1,0.6)
(5.2,0.9)
(4.25,1.2)
};
\end{axis}
\end{tikzpicture}
\end{document}

答案1

要控制栏高度,

\addplot[fill=blue,bar width=0.15cm] coordinates {

相关内容