컬러바에 잘못된 체크 표시

컬러바에 잘못된 체크 표시

다음을 기반으로 비머에서 범례를 생성하는 함수를 작성 중입니다.

  • 페이지에서의 위치
  • 최대값과 최소값
  • 사용할 컬러맵

예는 다음과 같습니다.

\documentclass[table]{beamer}

\usepackage{tikz,pgfplots}
\usetikzlibrary{calc}
\usetikzlibrary{backgrounds}

% Colormaps
\pgfplotsset{
    colormap={Legend1}{
        rgb255=(255, 113,   0),
        rgb255=(255, 227,   0),
        rgb255=(170, 255,   0),
        rgb255=( 57, 255,   0),
        rgb255=( 40, 255, 185),
        rgb255=(  0, 199, 221),
        rgb255=( 21, 121, 255),
    }
}

% Len of above/below triangle
\def\len{0.75cm}

% Horizontal Legend
\newcommand{\LegendH}[4]{
    \begin{tikzpicture}[remember picture,overlay]
        % Min/Max/Colormap
        \pgfmathsetmacro{\Min}{#2}
        \pgfmathsetmacro{\Max}{#3}
        \def\colormap{#4}

        % Tick distance
        \pgfmathsetmacro{\XTickDistance}{
            (\Min - \Max) / \pgfplotscolormapsizeof{\colormap}
        }

        % Above/Below
        \ifnum\pdfstrcmp{\colormap}{Legend1}=0
            \definecolor{Lcolor}{RGB}{192, 192, 192}
            \definecolor{Rcolor}{RGB}{255,   0,   0}
            \def\precision{2}
        \fi

        % Axis
        \begin{axis}[
        hide axis, scale only axis, height=0pt, width=0pt, % hide axis
        colormap name = \colormap,
        colorbar sampled,
        colorbar horizontal,
        point meta min=\Min,
        point meta max=\Max,
        colorbar style = {
            name = cb,
            at={(#1)}, anchor=center,
            samples = \pgfplotscolormapsizeof{\colormap} + 1,
            height = 0.5cm,
            width = 10cm,
            xtick style = {draw=none},
            xticklabel style = {
                text width = 2.5em,
                align = center,
                /pgf/number format/.cd,
                fixed,
                fixed zerofill,
                precision = \precision,
                /tikz/.cd
            },
            xtick distance=\XTickDistance,
        }
        ]
        \addplot [draw=none] coordinates {(0,0)};
        \end{axis}

        % Above/Below  triangle
        \foreach \i/\j in {south east/a, north east/b, north west/c, south west/d}
        {\coordinate (\j) at (current colorbar axis.\i);}
        \filldraw[fill=Lcolor] (a) -- ($(a)!0.5!(b)+(\len,0)$) -- (b);
        \filldraw[fill=Rcolor] (c) -- ($(c)!0.5!(d)+(-\len,0)$)-- (d);

        % Background
        \scoped[on background layer]
        \fill [white] ([shift={(-0.25cm,-0.5cm)}]cb.outer south west) rectangle ([shift={(+0.0cm,+0.5cm)}]cb.outer north east);
    \end{tikzpicture}
}   

\begin{document}
    \begin{frame}{Legend}
        \LegendH{$(current page.center)+(0cm, -2cm)$}{1.0}{2.0}{Legend1}
        \LegendH{$(current page.center)+(0cm, +0cm)$}{1.0}{3.0}{Legend1}
    \end{frame}
\end{document}

이것이 내가 얻는 것입니다: 결과

보시다시피 아래쪽 범례(1과 2 사이)가 맞습니다.

위쪽이 잘못되었습니다. 1에서 시작하여 3에서 끝나야 하며 틱은 1.00, 1.29, 1.57, 1.86, 2.14, 2.43, 2.71, 3.00이어야 합니다.

왜 이런 이상한 행동이 일어나는지 이해가 되지 않습니다.

감사해요

관련 정보