TikZ/PGFPlots, 축 없음을 사용하여 컬러바 내에서 ytick을 설정하는 데 문제가 있습니다.

TikZ/PGFPlots, 축 없음을 사용하여 컬러바 내에서 ytick을 설정하는 데 문제가 있습니다.

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

그림 1: 현재 결과

내 문제:-2e-3, -1,5e-3, -1e-3,...,2e-3과 같이 y-틱을 갖고 싶습니다.

예를 들어 다른 프로그램의 그림 2를 참조하세요.

그림 2: y 표시는 다음과 같아야 합니다.

$-2e-3$y-틱 과 같은 것을 사용하는 것은 작동하지 않습니다.

오류:! 패키지 PGF 수학 오류: 입력 '$-2^{-3}$'을 부동 소수점 숫자로 구문 분석할 수 없습니다. 죄송합니다. 읽을 수 없는 부분은 '$-2^{-3}$' 근처에 있었습니다.

지금까지 내 코드는 다음과 같습니다. (이 코드를 사용하면 위에 표시된 그림 1이 표시됩니다.)

\documentclass[tikz,border={12pt,12pt}]{standalone}
\usepackage{pgfplots}
\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}{m^2}$},     % Titel über Colorbar
        ylabel= {$\cdot e^{-3}$},           % Beschriftung seitlich, text                                                             gedreht
        samples=9,                  % Anzahl diskreter Schritte, so viele wie yticks
        width=15,                   % Breite der Colorbar (des farbigen Bereichs)
        height=220,                 % Höhe der Colorbar
        ytick={-2, -1.5, -1,..., 2},% yticks Angabe einzeln mit komma getrennt,                                               oder schrittweise mit 1,2,...,5
        point meta min=-2, %neu     % Beginn Colorbar, beachte yticks min
        point meta max=2, %neu      % Ende Colorbar, beachte yticks max
        yticklabel style={
            text width=2.5em,       % Abstand yticks zu colorbar
            align=right,            % 
        }
    }
]
\end{axis}
\end{tikzpicture}

\end{document}

내 문제와 내가하고 싶은 일을 이해하시기 바랍니다.

누군가가 y-tick 값을 2e^{-3}.

답변1

이를 달성하는 한 가지 방법은 다음을 수행하는 것입니다.

  1. meta범위 에 대한 실제 값을 사용하므로point meta min=-2e-3, point meta max=2e3
  2. 눈금 레이블의 전체 크기 조정을 끕니다.scaled y ticks = false
  3. siunitx숫자 형식을 매우 세밀하게 제어할 수 있는 패키지를 사용하여 눈금 값을 구문 분석하고 형식을 지정합니다 . 로드한 \usepackage{siunitx}다음 설정합니다.

    yticklabel={
        \num[
            scientific-notation = fixed,
            fixed-exponent = -3,
            output-exponent-marker = \text{e},
            round-integer-to-decimal = true,
            round-mode = places,
            round-precision = 1
        ]{\tick}
    }
    

\documentclass[tikz,border={12pt,12pt}]{standalone}
\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}{m^2}$},     % Titel über Colorbar gedreht
        samples=9,                  % Anzahl diskreter Schritte, so viele wie yticks
        width=15,                   % Breite der Colorbar (des farbigen Bereichs)
        height=220,                 % Höhe der Colorbar
        %ytick={-2, -1.5, -1,..., 2},% yticks Angabe einzeln mit komma getrennt,                                               oder schrittweise mit 1,2,...,5
        point meta min=-2e-3, %neu     % Beginn Colorbar, beachte yticks min
        point meta max=2e-3, %neu      % Ende Colorbar, beachte yticks max
        scaled y ticks = false,
        yticklabel={
            \num[
                scientific-notation = fixed,
                fixed-exponent = -3,
                output-exponent-marker = \text{e},
                round-integer-to-decimal = true,
                round-mode = places,
                round-precision = 1
            ]{\tick}
        },
        yticklabel style={
            text width=4em,       % Abstand yticks zu colorbar
            align=right,            % 
        }
    }
]
\end{axis}
\end{tikzpicture}

\end{document}

답변2

PSTricks 솔루션.

e 표기법 사용:

\documentclass{article}

\usepackage{multido,pstricks}

\definecolor{color1}{rgb}{0.68235,0,1}
\definecolor{color2}{rgb}{0,0.1216,1}
\definecolor{color3}{rgb}{0,0.69412,1}
\definecolor{color4}{rgb}{0,1,0.6863}
\definecolor{color5}{rgb}{0,1,0.098}
\definecolor{color6}{rgb}{0.557,1,0}
\definecolor{color7}{rgb}{1,0.8353,0}
\definecolor{color8}{rgb}{1,0.2275,0}
\definecolor{color9}{rgb}{1,0.02745,0}

\begin{document}

\begin{pspicture}(-0.33,-0.15)(2.3,8.7)
  \multido{\i = 1+1}{8}{\psframe[dimen = m, fillstyle = solid, fillcolor = color\i](!0 \i\space 1 sub)(0.5,\i)}
  \multido{\iA = 0+2, \iB = -2+1}{5}{\rput[r](1.9,\iA){$\iB\mathrm{e}^{-3}$}}
  \multido{\i = 1+2, \r = -1.5+1}{4}{\rput[r](1.9,\i){$\r\mathrm{e}^{-3}$}}
  \rput(0.25,8.5){$J$ in $\frac{A}{\textup{m}^{2}}$}
\end{pspicture}

\end{document}

출력1

제 생각에는 과학적 표기법을 사용하는 것이 더 좋습니다.

\documentclass{article}

\usepackage{multido,pstricks}

\definecolor{color1}{rgb}{0.68235,0,1}
\definecolor{color2}{rgb}{0,0.1216,1}
\definecolor{color3}{rgb}{0,0.69412,1}
\definecolor{color4}{rgb}{0,1,0.6863}
\definecolor{color5}{rgb}{0,1,0.098}
\definecolor{color6}{rgb}{0.557,1,0}
\definecolor{color7}{rgb}{1,0.8353,0}
\definecolor{color8}{rgb}{1,0.2275,0}
\definecolor{color9}{rgb}{1,0.02745,0}

\begin{document}

\begin{pspicture}(-0.33,-0.15)(2.3,8.7)
  \multido{\i = 1+1}{8}{\psframe[dimen = m, fillstyle = solid, fillcolor = color\i](!0 \i\space 1 sub)(0.5,\i)}
  \multido{\iA = 0+2, \iB = -2+1}{5}{\rput[r](2.3,\iA){$\iB \cdot 10^{-3}$}}
  \multido{\i = 1+2, \r = -1.5+1}{4}{\rput[r](2.3,\i){$\r \cdot 10^{-3}$}}
  \rput(0.25,8.5){$J$ in $\frac{A}{\textup{m}^{2}}$}
\end{pspicture}

\end{document}

출력2

관련 정보