pgfplots/tickz einfarbiger Balken mit Unterklammern

pgfplots/tickz einfarbiger Balken mit Unterklammern

Ich bin ein völliger Neuling bei tickz/pgfplot und mein Ziel ist es, einen einzelnen horizontalen Balken (mit Unterklammern) wie diesen zu erstellen:

Bildbeschreibung hier eingeben

Ich glaube, ich würde lieber mit beginnen pgfplotscolorbardrawstandalone, aber der Rest ist für mich ein echter Kampf. Kann jemand helfen?

Antwort1

Mit reinem TitankZ (ist nicht ganz einfach ...)Č

\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc, chains,
                decorations.pathreplacing, % must be after decorations.pathreplacing
                calligraphy
                }

\begin{document}
    \begin{tikzpicture}[
    node distance = 0pt,
      start chain = A going right,
      start chain = B going right,
BC/.style args = {#1/#2}{
    decorate,
    decoration={calligraphic brace, amplitude=6pt,
    pre =moveto, pre  length=1pt,
    post=moveto, post length=1pt,
    raise=#1},
    very thick,
    pen colour={#2}
    },
BL/.style = {font=\small, below=#1},
 M/.style args = {#1/#2}{baseline, fill=#1, 
    font=\small, label={[text height=1.2ex, text depth=0.2ex]right:#2}, 
    node distance=17mm},
 N/.style args = {#1/#2}{fill=#1, minimum width=#2, 
    minimum height=5mm, outer sep=0pt, node contents={}, 
    on chain=B},
                        ]

\node (a) [N=red/30mm];
\node (b) [N=orange/85mm];
\node (c) [N=purple/10mm];

\path   ([yshift=5mm] a.north west) --
    node (x) [M=orange/orange] {}
    node     [M=red/red, left=of x] {}
    node     [M=purple/purple, right=of x] {}
        ([yshift=5mm] c.north east);
    
\draw[BC=3pt/black] (a.south east) -- node[BL=7pt] {length = 30} (a.south west);
\draw[BC=3pt/black] (b.south east) -- node[BL=7pt] {length = 85} (b.south west);
\draw[BC=3pt/black] (c.south east) -- node[BL=7pt] {length = 10} (c.south west);
    \end{tikzpicture}
\end{document}

Bildbeschreibung hier eingeben

Nachtrag: Der pgfplotsCode ist etwas einfacher und deutlich kürzer:

\documentclass[margin=3mm]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{calc, chains,
                decorations.pathreplacing, % must be after decorations.pathreplacing
                calligraphy
                }
\pgfplotsset{compat=1.18}


\begin{document}
    \begin{tikzpicture}[
BC/.style = {
    decorate,
    decoration={calligraphic brace, amplitude=6pt,
    pre =moveto, pre  length=1pt,
    post=moveto, post length=1pt,
    raise=#1, mirror},
    very thick,
    pen colour={black}
    },
BL/.style = {font=\small, below=#1},
BL/.default= 5mm
                    ]
\begin{axis}[
x=1mm, 
axis lines=none,
%
xbar stacked,
bar width=5mm,
xmin=0,
%
legend style={at={(0.5,0.58)}, draw=none, anchor=south,
              legend columns=-1, font=\small,
              /tikz/every even column/.append style={column sep=1em}
              },
                ]
\addplot coordinates{(30,0)};
\addplot coordinates{(85,0)};
\addplot coordinates{(10,0)};
    \legend{blue, red, brown}
%
\draw[BC=3.3mm] (0,  0) -- node[BL] {length = 30} ++(30,0);
\draw[BC=3.3mm] (30, 0) -- node[BL] {length = 85} ++(85,0);
\draw[BC=3.3mm] (115,0) -- node[BL] {length = 10} ++(10,0);
\end{axis}
    \end{tikzpicture}
\end{document}

Das Ergebnis ist ähnlich wie zuvor:

Bildbeschreibung hier eingeben

verwandte Informationen