我尝试使用 pgfplots 绘制热图,但是如果 z 是对数的,我无法在热图附带的颜色条中获得正确的刻度值。10^-11 左右的数值来源是什么?数据文件中没有类似的东西。
文件
\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\usepackage{filecontents}
\begin{filecontents}{map.txt}
0.1 0 2.933100901655603E-6
0.1 10 1.2378929491530841E-5
0.1 20 2.0588051604902755E-5
0.1 30 2.7190941686966532E-5
0.1 40 3.290721897852047E-5
0.1 60 4.250275971734089E-5
0.1 80 5.0350197981567186E-5
0.1 100 5.681643648591518E-5
0.1 150 6.859558257512272E-5
0.1 200 7.652271637806553E-5
0.1 250 8.22752949739641E-5
0.1 300 8.668070617985642E-5
0.2 0 1.362157048411715E-5
0.2 10 1.4186557576426701E-5
0.2 20 1.9510106350903664E-5
0.2 30 2.3880991840192088E-5
0.2 40 2.7472817836855655E-5
0.2 60 3.282892845070262E-5
0.2 80 3.656164586607819E-5
0.2 100 3.944614546159667E-5
0.2 150 4.434691145348564E-5
0.2 200 4.730750444203243E-5
0.2 250 4.9180711846180925E-5
0.2 300 5.0512424521156164E-5
\end{filecontents}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
colormap/jet,
colorbar,
colorbar style={yticklabel=$10^{\pgfmathprintnumber{\tick}}$},
view={0}{90},
zmode=log]
\addplot3[surf,shader=interp] table[x index=0,y index=1,z index=2] {map.txt};
\end{axis}
\end{tikzpicture}
\end{document}
生成以下图像:
答案1
新答案
一个简单的解决方案就是不是直接使用对数 z 轴,但使用来计算该值z expr=log10(\thisrowno{2})
。
% used PGFPlots v1.15
\begin{filecontents}{map.txt}
0.1 0 2.933100901655603E-6
0.1 10 1.2378929491530841E-5
0.1 20 2.0588051604902755E-5
0.1 30 2.7190941686966532E-5
0.1 40 3.290721897852047E-5
0.1 60 4.250275971734089E-5
0.1 80 5.0350197981567186E-5
0.1 100 5.681643648591518E-5
0.1 150 6.859558257512272E-5
0.1 200 7.652271637806553E-5
0.1 250 8.22752949739641E-5
0.1 300 8.668070617985642E-5
0.2 0 1.362157048411715E-5
0.2 10 1.4186557576426701E-5
0.2 20 1.9510106350903664E-5
0.2 30 2.3880991840192088E-5
0.2 40 2.7472817836855655E-5
0.2 60 3.282892845070262E-5
0.2 80 3.656164586607819E-5
0.2 100 3.944614546159667E-5
0.2 150 4.434691145348564E-5
0.2 200 4.730750444203243E-5
0.2 250 4.9180711846180925E-5
0.2 300 5.0512424521156164E-5
\end{filecontents}
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
view={0}{90},
colormap/jet,
colorbar,
colorbar style={yticklabel=$10^{\pgfmathprintnumber{\tick}}$},
]
\addplot3 [
surf,
shader=interp,
] table [
x index=0,
y index=1,
z expr=log10(\thisrowno{2}), % <-- this does what you want
] {map.txt};
\end{axis}
\end{tikzpicture}
\end{document}
旧答案(旧问题)
PGFPlots 完全按照您的要求执行。您的数据文件包含 2.9e-6 到 8.7e-5 范围内的值。如果您写入,yticklabel=$10^{\pgfmathprintnumber{\tick}}$
您将获得该值。因此,您得到的不仅仅是颜色条顶部的值 2、4、...、8 和乘数 10^-5,而是 10^2、10^4、...、10^8。如果您另外有,zmode=log
您当然会得到\tick
ln(value),它给出的值约为 10^-5 -11,但因为yticklabel=$10^{\pgfmathprintnumber{\tick}}$
它写为 10^-11 ...
因此,只需注释掉引起问题的两行,一切就都好了,对吗?
% used PGFPlots v1.15
\begin{filecontents}{map.txt}
0.1 0 2.933100901655603E-6
0.1 10 1.2378929491530841E-5
0.1 20 2.0588051604902755E-5
0.1 30 2.7190941686966532E-5
0.1 40 3.290721897852047E-5
0.1 60 4.250275971734089E-5
0.1 80 5.0350197981567186E-5
0.1 100 5.681643648591518E-5
0.1 150 6.859558257512272E-5
0.1 200 7.652271637806553E-5
0.1 250 8.22752949739641E-5
0.1 300 8.668070617985642E-5
0.2 0 1.362157048411715E-5
0.2 10 1.4186557576426701E-5
0.2 20 1.9510106350903664E-5
0.2 30 2.3880991840192088E-5
0.2 40 2.7472817836855655E-5
0.2 60 3.282892845070262E-5
0.2 80 3.656164586607819E-5
0.2 100 3.944614546159667E-5
0.2 150 4.434691145348564E-5
0.2 200 4.730750444203243E-5
0.2 250 4.9180711846180925E-5
0.2 300 5.0512424521156164E-5
\end{filecontents}
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
view={0}{90},
colormap/jet,
colorbar,
% colorbar style={yticklabel=$10^{\pgfmathprintnumber{\tick}}$},
% zmode=log,
]
\addplot3[surf,shader=interp] table[x index=0,y index=1,z index=2] {map.txt};
\end{axis}
\end{tikzpicture}
\end{document}