![缩放非对称色彩图](https://linux22.com/image/430456/%E7%BC%A9%E6%94%BE%E9%9D%9E%E5%AF%B9%E7%A7%B0%E8%89%B2%E5%BD%A9%E5%9B%BE.png)
我想知道是否有一种自动化的方法来生成一个发散色彩图,其中心位于 0,与我想要绘制的数据无关?
我想到的方法是使用mesh min
和mesh max
值并使用绝对最大值来生成所需的输出。
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots,filecontents}
\usepgfplotslibrary{colormaps}
\usetikzlibrary{calc}
\pgfplotsset{
compat=newest,
/pgfplots/colormap={colmap}{
rgb255=(0,0,139)
rgb255=(0,0,255)
rgb255=(0,255,255)
rgb255=(255,255,255)
rgb255=(255,255,0)
rgb255=(255,0,0)
rgb255=(139,0,0)
}
}
\begin{filecontents}[overwrite]{test.txt}
x y z
1000 1000 0.28019
1002 1000 0.40177
1004 1000 0.86296
1006 1000 0.59342
1008 1000 0.27397
1010 1000 0.67336
1000 1002 0.5083
1002 1002 0.55867
1004 1002 0.94536
1006 1002 0.20572
1008 1002 0.33257
1010 1002 0.64346
1000 1004 0.05353
1002 1004 0.21822
1004 1004 0.25069
1006 1004 0.36525
1008 1004 0.78002
1010 1004 0.04127
1000 1006 0.57922
1002 1006 0.97888
1004 1006 0.54728
1006 1006 0.94287
1008 1006 0.83359
1010 1006 0.91652
1000 1008 0.28625
1002 1008 0.46143
1004 1008 0.67409
1006 1008 0.38048
1008 1008 0.82077
1010 1008 0.52705
1000 1010 0.25684
1002 1010 0.2017
1004 1010 0.80708
1006 1010 0.71639
1008 1010 0.85566
1010 1010 0.80574
\end{filecontents}
\def\zmin{-0.04127}
\def\zmax{0.97888}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
name=plot1,
title=without 'meta limits',
view={0}{90},
colorbar,
]
\addplot3[
surf,
shader=interp,
mesh/rows=3,
mesh/cols=6,
mesh/check=false,
point meta=z,
]
table[
x=x,
y=y,
z=z,
] {test.txt};
\end{axis}
\begin{axis}[
name=plot2,
at={($(plot1.east) + (3cm,0)$)},
anchor=west,
title=with 'meta limits',
view={0}{90},
colorbar,
]
\addplot3[
surf,
shader=interp,
mesh/rows=3,
mesh/cols=6,
mesh/check=false,
point meta=z,
point meta max= \zmax,
point meta min=-\zmax,
]
table[
x=x,
y=y,
z=z,
] {test.txt};
\end{axis}
\end{tikzpicture}
\end{document}
如果数据主要包含正值或负值,我不想在颜色条中显示相应的负值或正值。
答案1
我另外查看了手册并尝试了一下以color position
获得所需的输出。
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots,filecontents}
\usepgfplotslibrary{colormaps}
\usetikzlibrary{calc}
\begin{filecontents}[overwrite]{test.txt}
x y z
1000 1000 0.28019
1002 1000 0.40177
1004 1000 0.86296
1006 1000 0.59342
1008 1000 0.27397
1010 1000 0.67336
1000 1002 0.5083
1002 1002 0.55867
1004 1002 0.94536
1006 1002 0.20572
1008 1002 0.33257
1010 1002 0.64346
1000 1004 0.05353
1002 1004 0.21822
1004 1004 0.25069
1006 1004 0.36525
1008 1004 -0.78002
1010 1004 0.04127
1000 1006 0.57922
1002 1006 0.97888
1004 1006 0.54728
1006 1006 0.94287
1008 1006 0.83359
1010 1006 0.91652
1000 1008 -0.28625
1002 1008 0.46143
1004 1008 0.67409
1006 1008 0.38048
1008 1008 0.82077
1010 1008 0.52705
1000 1010 0.25684
1002 1010 0.2017
1004 1010 0.80708
1006 1010 0.71639
1008 1010 0.85566
1010 1010 1.80574
\end{filecontents}
\def\zmin{-0.78002}
\def\zmax{1.80574}
\pgfplotsset{%
compat=newest,
colormap={corr2D}{
rgb255=(0,0,139);
rgb255=(0,0,255);
rgb255=(0,255,255);
rgb255=(255,255,255);
rgb255=(255,255,0);
rgb255=(255,0,0);
rgb255=(139,0,0);
},
}
\begin{document}
\pgfmathsetmacro{\zlim}{abs(\zmin) > abs(\zmax) ? abs(\zmin) : abs(\zmax)}
\begin{tikzpicture}
\begin{axis}[
name=plot1,
title=without 'meta limits',
view={0}{90},
colormap name=corr2D,
colorbar,
]
\addplot3[
surf,
shader=interp,
mesh/rows=3,
mesh/cols=6,
mesh/check=false,
point meta=z,
]
table[
x=x,
y=y,
z=z,
] {test.txt};
\end{axis}
\begin{axis}[
name=plot2,
at={($(plot1.east) + (3cm,0)$)},
anchor=west,
title=with 'meta limits',
view={0}{90},
colormap name=corr2D,
colorbar,
]
\addplot3[
surf,
shader=interp,
mesh/rows=3,
mesh/cols=6,
mesh/check=false,
point meta=z,
point meta max= \zmax,
point meta min=-\zmax,
]
table[
x=x,
y=y,
z=z,
] {test.txt};
\end{axis}
\begin{axis}[
name=plot2,
at={($(plot2.east) + (3cm,0)$)},
anchor=west,
title=with 'meta limits' and scaling,
view={0}{90},
colorbar,
colormap={corr2d2}{
rgb255(3/3*\zmin/\zlim)=(0,0,139);
rgb255(2/3*\zmin/\zlim)=(0,0,255);
rgb255(1/3*\zmin/\zlim)=(0,255,255);
rgb255(0)=(255,255,255);
rgb255(1/3*\zmax/\zlim)=(255,255,0);
rgb255(2/3*\zmax/\zlim)=(255,0,0);
rgb255(3/3*\zmax/\zlim)=(139,0,0);
},
]
\addplot3[
surf,
shader=interp,
mesh/rows=3,
mesh/cols=6,
mesh/check=false,
point meta=z,
point meta max=\zmax,
point meta min=\zmin,
]
table[
x=x,
y=y,
z=z,
] {test.txt};
\end{axis}
\end{tikzpicture}
\end{document}
\zmax
我可以从我的输出中获取值\zmin
,在那里我模拟数据,或者从我的先前的问题并比较它们以得出它们的绝对值的最大值(\zlim
)。