Проблемы с установкой ytick в цветовой шкале с использованием TikZ/PGFPlots, нет оси

Проблемы с установкой ytick в цветовой шкале с использованием TikZ/PGFPlots, нет оси

Я хочу сделать цветовую шкалу в TikZ без какой-либо оси рядом. Вот что я получил на данный момент, используя помощь, предоставленную этим прекрасным форумом.

Рис 1: результат на данный момент

Моя проблема:Я хочу, чтобы y-тик был следующим: -2e-3, -1,5e-3, -1e-3,...,2e-3.

См., например, рисунок 2 из другой программы;

Рис 2: y-галочка, как это должно выглядеть

Использование чего-то вроде $-2e-3$y-tick не работает;

Ошибка:! Ошибка пакета PGF Math: Не удалось проанализировать ввод '$-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

Связанный контент