首页 > 解决方案 > 创建条形图,条形总和高达 100

问题描述

我尝试使用 PGFPLOTS 在 LaTeX 中创建一个条形图,其中条形的总和为 100%

下半部分(比如说 30%)应该是绿色的。

中间部分(比如说 20%)应该是黄色的。

上半部分(比如说 50%)应该是红色的。

我可以用这些数字并排生成图,但不能堆叠

有人知道如何解决这个问题吗?

提前致谢!

标签: latexpgfplots

解决方案


答案在“4.5.9 Stacked Plots”中的 pgfplots 手册中。(感谢@samcarter_is_at_topanswers.xyz 的提示)

我在本手册章节中使用的代码是这样的:

\begin{tikzpicture}
\begin{axis}[ybar stacked]
  \addplotcoordinates{(0,1) (1,1) (2,3) (3,2) (4,1.5)};
  \addplotcoordinates{(0,1) (1,1) (2,3) (3,2) (4,1.5)};
  \addplotcoordinates{(0,1) (1,1) (2,3) (3,2) (4,1.5)};
\end{axis}
\end{tikzpicture}

推荐阅读