Tikz 中带有自定义标签的条形图

Tikz 中带有自定义标签的条形图

有人知道如何在 Tikz 中创建带有自定义 x 标签的条形图,并且每个条形的颜色都不同(只要交替的条形颜色相同且相邻的条形颜色不同,实际上并不关心颜色)?

条形图

任何形式的帮助都将不胜感激。谢谢!

答案1

\documentclass[ tikz,
                border=3mm]{standalone}
\usetikzlibrary{chains}

\begin{document}
\begin{tikzpicture}[
  node distance = 0mm,
    start chain = A going right,
bar/.style args = {#1/#2}{draw, %
    fill=#1, minimum width=#2, 
    minimum height=1em, outer sep=0mm,
    node contents={}, on chain}
                    ]
\node[bar=blue!30/13mm];
\node[bar=red!30/21mm];
\node[bar=blue!30/13mm];
\node[bar=red!30/21mm];
    \draw[->]   ([xshift=-3mm]A-1.south west) -- ([xshift=7mm]A-4.south east);
    \draw[->]   ([yshift=-3mm]A-1.south west) -- ([yshift=7mm]A-1.north west);
\path   (A-1.south east) node[below] {$T$}
        (A-2.south east) node[below] {$T{+}L$}
        (A-3.south east) node[below] {$2T{+}L$}
        (A-4.south east) node[below] {$2T{+}2L$};
\end{tikzpicture}%
\end{document}

在此处输入图片描述

相关内容