2

How can I change the mantissa separator in my MWE from \cdot to \times?

The MWE needs to be compiled with the -shell-escape flag.

\documentclass[preview]{standalone}%
%
\usepackage{caption}%
\usepackage{subcaption}%
\usepackage{pgfplots}%
  \usepgfplotslibrary{groupplots}%
  \pgfplotsset{compat=1.16}%
\usepackage{filecontents}%
%
\begin{filecontents*}{data1.dat}
a,b,c
100,1,1E+16
100,2,2E+17
100,3,5E+18

200,1,1E+16
200,2,2E+15
200,3,5E+14

300,1,1E+14
300,2,2E+13
300,3,5E+12
\end{filecontents*}
%
\begin{filecontents*}{data2.dat}
a,b,c
100,1,3
100,2,4
100,3,5

200,1,2
200,2,3
200,3,3

300,1,1
300,2,2
300,3,2
\end{filecontents*}
%
\begin{document}
%
\begin{figure}
  \centering
  \begin{tikzpicture}
    \begin{groupplot}[%
      width=0.35\textwidth,%
      title style={%
        at={(xticklabel cs:0.5)},%
        below=4ex,%
        text width=0.35\textwidth,%
      },%
      group style={%
        group size=1 by 2,%
        horizontal sep=4em,vertical sep=13ex,%
      },%
      scale only axis,%
      tick scale binop=\times,%
      xmin={100},xmax={300},%
      ymin={1},ymax={3},%
      view={0}{90},%
      colormap/viridis,%
    ]%
      \pgfmathtruncatemacro{\zminA}{12}% "12" = 1.E+12
      \pgfmathtruncatemacro{\zmaxA}{18}%
      %
      \pgfmathtruncatemacro{\zminB}{1}%
      \pgfmathtruncatemacro{\zmaxB}{5}%
      %
      %%%%%%%%%%%%
      % subfig 1 %
      %%%%%%%%%%%%
      \nextgroupplot[%
        title={\subcaption{}},%
        %
        zmode=log,log base z=10,zminorticks=false,%
        zmin={1.E\zminA},zmax={1.E\zmaxA},%
        %
        xlabel={X1},ylabel={Y1},zlabel={Z1},%
        %
        point meta rel=per plot,%
        point meta min={1.E\zminA},point meta max={1.E\zmaxA},%
        colorbar,%
        colorbar style={
          ymode=log,
          ymin={1.E\zminA},ymax={1.E\zmaxA},%
          yminorticks=false,%
          ylabel={Z1},%
        },%
      ]%
        \addplot3[%
          surf,%
          point meta min={\zminA},point meta max={\zmaxA},%
        ]%
          table[%
            x=a,y=b,z=c,%
            col sep=comma,%
          ]{data1.dat};%
          %
        \addplot3[%
          % modified version of https://tex.stackexchange.com/a/193707
          contour/label node code/.code={%
            \node{%
              \pgfkeys{%
                /pgf/fpu=true,%
                /pgf/number format/.cd,
                sci,%
                % sci generic={%
                %   mantissa sep=\times,%
                %   exponent={10^{##1}},%
                % },%
              }%
              \pgfmathpow{10}{##1}%
              \pgfmathprintnumber{\pgfmathresult}%
            };%
          },%
          contour gnuplot={%
            draw color=black,%
            levels={4.E14,2.E15,3.E16},% random levels for test
          },%
        ]%
          table[%
            x=a,y=b,z=c,%
            col sep=comma,%
          ]{data1.dat};%
          %
      %%%%%%%%%%%%
      % subfig 2 %
      %%%%%%%%%%%%
      \nextgroupplot[%
        title={\subcaption{}},%
        colorbar,%
        colorbar style={
            ylabel={Z2},%
        },%
        zmin={\zminB},zmax={\zmaxB},%
        ztick={\zminB,\zmaxB},%
        %
          xlabel={X2},ylabel={Y2},zlabel={Z2},%
      ]%
      %
        \addplot3[%
          surf,%
          point meta min=\zminB,point meta max=\zmaxB,%
        ]%
          table[%
            x=a,y=b,z=c,%
            col sep=comma,%
          ]{data2.dat};%
          %
        \addplot3[%
          contour gnuplot={%
            draw color=black,%
            contour label style={%
              every node/.append style={text=black}
            },%
          },%
          point meta min=\zminB,point meta max=\zmaxB,%
        ]%
          table[%
            x=a,y=b,z=c,%
            col sep=comma,%
          ]{data2.dat};%
          %
    \end{groupplot}%
  \end{tikzpicture}%
\caption{my caption}
\label{fig:myfig}
\end{figure}
%
\end{document}

I tried to adapt Alex's contour label manipulation to

contour/label node code/.code={%
  \node{%
    \pgfkeys{%
      /pgf/fpu=true,%
      /pgf/number format/.cd,
      sci,%
      sci generic={%
        mantissa sep=\times,%
        exponent={10^{##1}},%
      },%
    }%
    \pgfmathpow{10}{##1}%
    \pgfmathprintnumber{\pgfmathresult}%
  };%
},%

Unfortunately, this yields a wrong exponent. Skipping the exponent setting in sci generic does not work either.

2
  • Isn't the dot here just the decimal indicator, so you could leave it out or use e.g. 1.0E+15?
    – albert
    Aug 9, 2019 at 12:19
  • I guess you are talking about the formatting of the third column in data1.dat. The dot does not matter. I removed it for clarity. As you can see, the MWE yields the same result. Aug 9, 2019 at 12:32

1 Answer 1

1

One can always use \pgfmathfloatparsenumber and \pgfmathfloattomacro to decompose numbers in their "atoms" and recombine them in any way you want. This may not be the quickest way to achieve this but it is very general.

\documentclass[preview]{standalone}%
%
\usepackage{caption}%
\usepackage{subcaption}%
\usepackage{pgfplots}%
  \usepgfplotslibrary{groupplots}%
  \pgfplotsset{compat=1.16}%
\usepackage{filecontents}%
%
\begin{filecontents*}{data1.dat}
a,b,c
100,1,1E+16
100,2,2E+17
100,3,5E+18

200,1,1E+16
200,2,2E+15
200,3,5E+14

300,1,1E+14
300,2,2E+13
300,3,5E+12
\end{filecontents*}
%
\begin{filecontents*}{data2.dat}
a,b,c
100,1,3
100,2,4
100,3,5

200,1,2
200,2,3
200,3,3

300,1,1
300,2,2
300,3,2
\end{filecontents*}
%
\begin{document}
%
\begin{figure}
  \centering
  \begin{tikzpicture}
    \begin{groupplot}[%
      width=0.35\textwidth,%
      title style={%
        at={(xticklabel cs:0.5)},%
        below=4ex,%
        text width=0.35\textwidth,%
      },%
      group style={%
        group size=1 by 2,%
        horizontal sep=4em,vertical sep=13ex,%
      },%
      scale only axis,%
      tick scale binop=\times,%
      xmin={100},xmax={300},%
      ymin={1},ymax={3},%
      view={0}{90},%
      colormap/viridis,%
    ]%
      \pgfmathtruncatemacro{\zminA}{12}% "12" = 1.E+12
      \pgfmathtruncatemacro{\zmaxA}{18}%
      %
      \pgfmathtruncatemacro{\zminB}{1}%
      \pgfmathtruncatemacro{\zmaxB}{5}%
      %
      %%%%%%%%%%%%
      % subfig 1 %
      %%%%%%%%%%%%
      \nextgroupplot[%
        title={\subcaption{}},%
        %
        zmode=log,log base z=10,zminorticks=false,%
        zmin={1.E\zminA},zmax={1.E\zmaxA},%
        %
        xlabel={X1},ylabel={Y1},zlabel={Z1},%
        %
        point meta rel=per plot,%
        point meta min={1.E\zminA},point meta max={1.E\zmaxA},%
        colorbar,%
        colorbar style={
          ymode=log,
          ymin={1.E\zminA},ymax={1.E\zmaxA},%
          yminorticks=false,%
          ylabel={Z1},%
        },%
      ]%
        \addplot3[%
          surf,%
          point meta min={\zminA},point meta max={\zmaxA},%
        ]%
          table[%
            x=a,y=b,z=c,%
            col sep=comma,%
          ]{data1.dat};%
          %
        \addplot3[%
          % modified version of https://tex.stackexchange.com/a/193707
          contour/label node code/.code={%
            \node{%
              \pgfkeys{%
                /pgf/fpu=true,%
                /pgf/number format/.cd,
                fixed
                %sci,%
                % sci generic={%
                %   mantissa sep=\times,%
                %   exponent={10^{##1}},%
                % },%
              }%
              \pgfmathpow{10}{##1}%
              \pgfmathfloatparsenumber{\pgfmathresult}%
              \pgfmathfloattomacro{\pgfmathresult}{\F}{\M}{\E}%
              $\pgfmathprintnumber{\M}\times10^{\E}$%
            };%
          },%
          contour gnuplot={%
            draw color=black,%
            levels={4.E14,2.E15,3.E16},% random levels for test
          },%
        ]%
          table[%
            x=a,y=b,z=c,%
            col sep=comma,%
          ]{data1.dat};%
          %
      %%%%%%%%%%%%
      % subfig 2 %
      %%%%%%%%%%%%
      \nextgroupplot[%
        title={\subcaption{}},%
        colorbar,%
        colorbar style={
            ylabel={Z2},%
        },%
        zmin={\zminB},zmax={\zmaxB},%
        ztick={\zminB,\zmaxB},%
        %
          xlabel={X2},ylabel={Y2},zlabel={Z2},%
      ]%
      %
        \addplot3[%
          surf,%
          point meta min=\zminB,point meta max=\zmaxB,%
        ]%
          table[%
            x=a,y=b,z=c,%
            col sep=comma,%
          ]{data2.dat};%
          %
        \addplot3[%
          contour gnuplot={%
            draw color=black,%
            contour label style={%
              every node/.append style={text=black}
            },%
          },%
          point meta min=\zminB,point meta max=\zmaxB,%
        ]%
          table[%
            x=a,y=b,z=c,%
            col sep=comma,%
          ]{data2.dat};%
          %
    \end{groupplot}%
  \end{tikzpicture}%
\caption{my caption}
\label{fig:myfig}
\end{figure}
%
\end{document}

enter image description here

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .