如何将 MWE 中的尾数分隔符从 \cdot 更改为 \times?
MWE 需要使用该-shell-escape
标志进行编译。
\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}
我尝试去适应Alex 的轮廓标签操作到
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}%
};%
},%
不幸的是,这会产生错误的指数。跳过exponent
设置sci generic
也不起作用。
答案1
总是可以使用\pgfmathfloatparsenumber
和\pgfmathfloattomacro
将数字分解为“原子”,然后以任何你想要的方式重新组合它们。这可能不是实现此目的的最快方法,但它非常通用。
\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}