pgfplots/tickz 밑괄호가 있는 단일 색상 막대

pgfplots/tickz 밑괄호가 있는 단일 색상 막대

나는 Tickz/pgfplot을 처음 접했고 내 목표는 다음과 같이 단일 수평 막대(밑괄호 포함)를 만드는 것입니다.

여기에 이미지 설명을 입력하세요

나는 차라리 로 시작하고 싶지만 pgfplotscolorbardrawstandalone나머지는 나에게 정말 힘든 일이다. 누구든지 도와줄 수 있나요?

답변1

순수 Ti 함유케이Z (별로 간단하지 않습니다...)체

\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}

여기에 이미지 설명을 입력하세요

부록: 코드 pgfplots는 좀 더 간단하고 훨씬 짧습니다.

\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}

결과는 이전과 유사합니다.

여기에 이미지 설명을 입력하세요

관련 정보