TikZ/PGFPlots, 축 없음을 사용하여 컬러바 내의 정의된 위치에 ytick 설정

TikZ/PGFPlots, 축 없음을 사용하여 컬러바 내의 정의된 위치에 ytick 설정

어제 나는 첫 번째 질문을 올렸습니다 (TikZ/PGFPlots, 축 없음을 사용하여 컬러바 내에서 ytick을 설정하는 데 문제가 있습니다.) 정말 환상적인 답변을 얻었습니다. 이제 내가 원하는 대로 작동합니다. 하지만 아직 작은 문제가 남아 있고 이 문제를 해결하기에는 너무 멍청한 것 같습니다. 등록(이제 작동합니다!) 및 포럼 상태에 문제가 발생하여 마지막 게시물에 댓글을 달 수 없습니다.

이제 내 문제는 TikZ에서 옆에 축 없이 컬러바를 만들고 싶습니다. 이것이 제가 이 슈퍼 포럼에서 제공하는 도움말을 사용하여 지금까지 얻은 것입니다.

컬러바의 실제 상태

하지만 그림 2에 표시된 것처럼 막대의 최소값 7.50e6, 그 다음 8.75e6, 1e7, ...에서 막대의 최대값(1.75e7)까지 정의된 위치에 yticks를 설정하고 싶습니다. 그림 2는 yticks에 관해 내가 원하는 솔루션을 보여줍니다.

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

yticks를 어떻게 자체 정의할 수 있나요?

지금까지 내 코드는 다음과 같습니다.

\documentclass[12pt,a4paper,oneside]{report}
\usepackage{tikz}
\usepackage{pgfplots, siunitx}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
    hide axis,
    scale only axis,                % 
    height=0pt,                     % Grafik auf größe null
    width=0pt,                      % Grafik auf größe null
    colorbar sampled,               % Diskrete Stufung
    colormap={mymap}{[1pt] rgb(0pt)=(0.68235,0,1);
            rgb(9pt)=(0,0.1216, 1);
            rgb(17pt)=(0, 0.69412, 1); 
            rgb(26pt)=(0, 1, 0.6863); 
            rgb(34pt)=(0, 1, 0.098); 
            rgb(43pt)=(0.557,1,0); 
            rgb(51pt)=(1, 0.8353, 0); 
            rgb(60pt)=(1, 0.2275, 0);  
            rgb(63pt)=(1,0.02745,0)},
    colorbar style={
        title={$J$ in $\frac{A}{\si{\square\m}}$},     % Titel über Colorbar gedreht si unit m^2
        %title={$J$ in $\frac{A}{m^{2}}$},              % Titel über Colorbar gedreht
        samples=75,                  % Anzahl diskreter Schritte, so viele wie yticks
        width=15,                   % Breite der Colorbar (des farbigen Bereichs)
        height=220,                 % Höhe der Colorbar
        point meta min=7500000, %neu     % Beginn Colorbar, beachte yticks min
        point meta max=17500000, %neu      % Ende Colorbar, beachte yticks max
        scaled y ticks = false,
        yticklabel={
            \num[
                %scientific-notation = fixed,
                scientific-notation = true,
                %fixed-exponent = 5,
                exponent-product=\cdot,
                %output-exponent-marker = \text{e},
                round-integer-to-decimal = true,
                round-mode = figures,
                round-precision = 3,
            ]{\tick}
        },
        yticklabel style={
            text width=4em,       % Abstand yticks zu colorbar
            align=right,            %          
        }
    }
]
\end{axis}
\end{tikzpicture}

\end{document}

당신이 나를 도울 수 있기를 바랍니다. 많은 감사드립니다!

답변1

개인적으로 나는 이것이 매우 유용한 틱 위치라고 생각하지 않지만, 이를 얻을 수 있는 방법은 다음과 같습니다.

가장 간단한 방법은 "무차별 대입 방법"입니다. ytick = {7.5e6, 8.75e6, 1e7, 1.125e7, 1.25e7, 1.375e7, 1.5e7, 1.625e7, 1.75e7}모든 눈금 위치를 수동으로 지정하도록 설정합니다.

그러나 이는 그다지 유연하지 않기 때문에 foreach. 그러나 이 메커니즘은 그렇게 큰 숫자를 처리할 수 없는 기본 TeX 산술을 사용하기 때문에 오류 ytick = {7.5e6, 8.75e6, ..., 1.75e7}와 함께 실패합니다. dimension too large따라서 몇 가지 중간 단계를 사용해야 합니다.

  • 이전에 말한 것과는 반대로 축 제한을 배율 단위로 지정합니다.

    point meta min=7.5,
    point meta max=17.5
    
  • 이를 통해 다음 구문을 사용하여 눈금 위치를 지정할 수 있습니다 foreach.

    ytick = {7.5, 8.75, ..., 17.5}
    
  • 눈금 레이블 내에서 눈금 값을 다시 조정할 수 있습니다.

    yticklabel={
    \pgfkeys{/pgf/fpu=true, /pgf/fpu/output format=fixed} % Necessary for handling large values
    \pgfmathparse{\tick*1e6} % Scale the tick values
        \num[
            scientific-notation = true,
            exponent-product=\cdot,
            round-integer-to-decimal = true,
            round-mode = places,
            round-precision = 3,
        ]{\pgfmathresult}
    

\documentclass[12pt,a4paper,oneside]{report}
\usepackage{tikz}
\usepackage{pgfplots, siunitx}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
    hide axis,
    scale only axis,                % 
    height=0pt,                     % Grafik auf größe null
    width=0pt,                      % Grafik auf größe null
    colorbar sampled,               % Diskrete Stufung
    colormap={mymap}{[1pt] rgb(0pt)=(0.68235,0,1);
            rgb(9pt)=(0,0.1216, 1);
            rgb(17pt)=(0, 0.69412, 1); 
            rgb(26pt)=(0, 1, 0.6863); 
            rgb(34pt)=(0, 1, 0.098); 
            rgb(43pt)=(0.557,1,0); 
            rgb(51pt)=(1, 0.8353, 0); 
            rgb(60pt)=(1, 0.2275, 0);  
            rgb(63pt)=(1,0.02745,0)},
    colorbar style={
        title={$J$ in $\frac{A}{\si{\square\m}}$},     % Titel über Colorbar gedreht si unit m^2
        %title={$J$ in $\frac{A}{m^{2}}$},              % Titel über Colorbar gedreht
        samples=75,                  % Anzahl diskreter Schritte, so viele wie yticks
        width=15,                   % Breite der Colorbar (des farbigen Bereichs)
        height=220,                 % Höhe der Colorbar
        point meta min=7.5, %neu     % Beginn Colorbar, beachte yticks min
        point meta max=17.5, %neu      % Ende Colorbar, beachte yticks max
        scaled y ticks = false,
       ytick = {7.5, 8.75, ..., 17.5},
        yticklabel={
    \pgfkeys{/pgf/fpu=true, /pgf/fpu/output format=fixed}
    \pgfmathparse{\tick*1e6}
            \num[
                %scientific-notation = fixed,
                scientific-notation = true,
                %fixed-exponent = 5,
                exponent-product=\cdot,
                %output-exponent-marker = \text{e},
                round-integer-to-decimal = true,
                round-mode = places,
                round-precision = 3,
            ]{\pgfmathresult}
        },
        yticklabel style={
            text width=4em,       % Abstand yticks zu colorbar
            align=right,            %          
        }
    }
]
\end{axis}
\end{tikzpicture}

\end{document}

1E10보다 큰 숫자를 처리해야 하는 경우 siunitx과학적 형식을 사용하여 숫자를 표시하려고 하면 질식하게 됩니다. 이 경우 PGF 숫자 파서로 대체할 수 있습니다. PGF 숫자 파서는 만큼 강력하지는 않지만 siunitx상당한 양의 사용자 정의도 허용합니다.

\pgfmathparse{\tick*1e6}
\pgfmathprintnumber{\pgfmathresult}

관련 정보