来自文件中 XYZ 数据点的热图

来自文件中 XYZ 数据点的热图

我想使用插值法根据文件中的数据制作热图或密度图。我一直在测试 pgfplots 手册中的不同选项(第 4.6.7 节“具有显式颜色的表面图”),但未能找到解决方案。

例如,以下内容给出编译错误:

\documentclass{article}
% \usepackage{pstricks-add}
% \usepackage[svgnames,pdf]{pstricks}
%
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.15}
\usepgfplotslibrary{patchplots}
\usepackage{filecontents}
\usepackage{pgfplotstable}

\begin{filecontents*}{dfsa3c.dat}
0.12    0.5 0.
0.12    1.5 0.
0.12    2.5 0.
0.12    3.5 0.
0.12    4.5 0.
0.12    5.5 0.
0.12    6.5 0.
0.12    7.5 0.
0.12    8.5 0.
0.12    9.5 0.
0.12    10.5    0.
0.12    11.5    0.
0.12    12.5    0.
0.12    13.5    0.
0.12    14.5    0.
0.12    15.5    0.
0.12    16.5    0.
0.12    17.5    0.
0.12    18.5    0.
0.16    0.5 0.
0.16    1.5 0.
0.16    2.5 0.
0.16    3.5 0.
0.16    4.5 0.
0.16    5.5 0.
0.16    6.5 0.
0.16    7.5 0.
0.16    8.5 0.
0.16    9.5 0.
0.16    10.5    0.
0.16    11.5    0.
0.16    12.5    0.
0.16    13.5    0.
0.16    14.5    0.
0.16    15.5    0.
0.16    16.5    0.
0.16    17.5    0.
0.16    18.5    0.
0.2 0.5 0.
0.2 1.5 0.
0.2 2.5 0.
0.2 3.5 0.
0.2 4.5 0.
0.2 5.5 0.
0.2 6.5 0.
0.2 7.5 0.
0.2 8.5 0.
0.2 9.5 0.
0.2 10.5    0.
0.2 11.5    0.
0.2 12.5    0.
0.2 13.5    0.
0.2 14.5    0.
0.2 15.5    0.
0.2 16.5    0.
0.2 17.5    0.
0.2 18.5    0.
0.24    0.5 0.
0.24    1.5 0.
0.24    2.5 0.
0.24    3.5 0.
0.24    4.5 0.
0.24    5.5 0.
0.24    6.5 0.
0.24    7.5 0.
0.24    8.5 0.
0.24    9.5 0.012333333333333333
0.24    10.5    0.101
0.24    11.5    0.2747278202455409
0.24    12.5    0.46103719793646486
0.24    13.5    0.5046684223126646
0.24    14.5    0.483661499790532
0.24    15.5    0.5092097445038621
0.24    16.5    0.5
0.24    17.5    0.5021666666666667
0.24    18.5    0.506
0.28    0.5 0.
0.28    1.5 0.
0.28    2.5 0.
0.28    3.5 0.
0.28    4.5 0.
0.28    5.5 0.
0.28    6.5 0.0006666666666666666
0.28    7.5 0.035
0.28    8.5 0.4125
0.28    9.5 0.9543333333333334
0.28    10.5    1.
0.28    11.5    1.
0.28    12.5    1.
0.28    13.5    1.
0.28    14.5    1.
0.28    15.5    1.
0.28    16.5    1.
0.28    17.5    1.
0.28    18.5    1.
0.32    0.5 0.
0.32    1.5 0.
0.32    2.5 0.
0.32    3.5 0.
0.32    4.5 0.
0.32    5.5 0.00525
0.32    6.5 0.4053333333333333
0.32    7.5 0.907
0.32    8.5 0.996
0.32    9.5 1.
0.32    10.5    1.
0.32    11.5    1.
0.32    12.5    1.
0.32    13.5    1.
0.32    14.5    1.
0.32    15.5    1.
0.32    16.5    1.
0.32    17.5    1.
0.32    18.5    1.
0.36    0.5 0.
0.36    1.5 0.
0.36    2.5 0.
0.36    3.5 0.
0.36    4.5 0.
0.36    5.5 0.1665
0.36    6.5 0.9516666666666667
0.36    7.5 1.
0.36    8.5 1.
0.36    9.5 1.
0.36    10.5    1.
0.36    11.5    1.
0.36    12.5    1.
0.36    13.5    1.
0.36    14.5    1.
0.36    15.5    1.
0.36    16.5    1.
0.36    17.5    1.
0.36    18.5    1.
0.4 0.5 0.
0.4 1.5 0.
0.4 2.5 0.
0.4 3.5 0.0007524454477050414
0.4 4.5 0.07252856433184302
0.4 5.5 0.71425
0.4 6.5 0.9996666666666667
0.4 7.5 1.
0.4 8.5 1.
0.4 9.5 1.
0.4 10.5    1.
0.4 11.5    1.
0.4 12.5    1.
0.4 13.5    1.
0.4 14.5    1.
0.4 15.5    1.
0.4 16.5    1.
0.4 17.5    1.
0.4 18.5    1.
0.44    0.5 0.
0.44    1.5 0.
0.44    2.5 0.
0.44    3.5 0.013
0.44    4.5 0.489
0.44    5.5 0.988
0.44    6.5 1.
0.44    7.5 1.
0.44    8.5 1.
0.44    9.5 1.
0.44    10.5    1.
0.44    11.5    1.
0.44    12.5    1.
0.44    13.5    1.
0.44    14.5    1.
0.44    15.5    1.
0.44    16.5    1.
0.44    17.5    1.
0.44    18.5    1.
0.48    0.5 0.
0.48    1.5 0.
0.48    2.5 0.
0.48    3.5 0.1725
0.48    4.5 0.9245
0.48    5.5 0.99925
0.48    6.5 1.
0.48    7.5 1.
0.48    8.5 1.
0.48    9.5 1.
0.48    10.5    1.
0.48    11.5    1.
0.48    12.5    1.
0.48    13.5    1.
0.48    14.5    1.
0.48    15.5    1.
0.48    16.5    1.
0.48    17.5    1.
0.48    18.5    1.
0.52    0.5 0.
0.52    1.5 0.
0.52    2.5 0.001
0.52    3.5 0.522
0.52    4.5 1.
0.52    5.5 1.
0.52    6.5 1.
0.52    7.5 1.
0.52    8.5 1.
0.52    9.5 1.
0.52    10.5    1.
0.52    11.5    1.
0.52    12.5    1.
0.52    13.5    1.
0.52    14.5    1.
0.52    15.5    1.
0.52    16.5    1.
0.52    17.5    1.
0.52    18.5    1.
0.56    0.5 0.
0.56    1.5 0.
0.56    2.5 0.0045
0.56    3.5 0.758137205808713
0.56    4.5 0.9990029910269193
0.56    5.5 1.
0.56    6.5 1.
0.56    7.5 1.
0.56    8.5 1.
0.56    9.5 1.
0.56    10.5    1.
0.56    11.5    1.
0.56    12.5    1.
0.56    13.5    1.
0.56    14.5    1.
0.56    15.5    1.
0.56    16.5    1.
0.56    17.5    1.
0.56    18.5    1.
0.6 0.5 0.
0.6 1.5 0.
0.6 2.5 0.055
0.6 3.5 0.927122464312547
0.6 4.5 1.
0.6 5.5 1.
0.6 6.5 1.
0.6 7.5 1.
0.6 8.5 1.
0.6 9.5 1.
0.6 10.5    1.
0.6 11.5    1.
0.6 12.5    1.
0.6 13.5    1.
0.6 14.5    1.
0.6 15.5    1.
0.6 16.5    1.
0.6 17.5    1.
0.6 18.5    1.
0.64    0.5 0.
0.64    1.5 0.
0.64    2.5 0.2115
0.64    3.5 0.9932364729458918
0.64    4.5 1.
0.64    5.5 1.
0.64    6.5 1.
0.64    7.5 1.
0.64    8.5 1.
0.64    9.5 1.
0.64    10.5    1.
0.64    11.5    1.
0.64    12.5    1.
0.64    13.5    1.
0.64    14.5    1.
0.64    15.5    1.
0.64    16.5    1.
0.64    17.5    1.
0.64    18.5    1.
0.68    0.5 0.
0.68    1.5 0.
0.68    2.5 0.384
0.68    3.5 0.999498997995992
0.68    4.5 1.
0.68    5.5 1.
0.68    6.5 1.
0.68    7.5 1.
0.68    8.5 1.
0.68    9.5 1.
0.68    10.5    1.
0.68    11.5    1.
0.68    12.5    1.
0.68    13.5    1.
0.68    14.5    1.
0.68    15.5    1.
0.68    16.5    1.
0.68    17.5    1.
0.68    18.5    1.
0.72    0.5 0.
0.72    1.5 0.
0.72    2.5 0.5045
0.72    3.5 1.
0.72    4.5 1.
0.72    5.5 1.
0.72    6.5 1.
0.72    7.5 1.
0.72    8.5 1.
0.72    9.5 1.
0.72    10.5    1.
0.72    11.5    1.
0.72    12.5    1.
0.72    13.5    1.
0.72    14.5    1.
0.72    15.5    1.
0.72    16.5    1.
0.72    17.5    1.
0.72    18.5    1.
0.76    0.5 0.
0.76    1.5 0.0005
0.76    2.5 0.6215
0.76    3.5 1.
0.76    4.5 1.
0.76    5.5 1.
0.76    6.5 1.
0.76    7.5 1.
0.76    8.5 1.
0.76    9.5 1.
0.76    10.5    1.
0.76    11.5    1.
0.76    12.5    1.
0.76    13.5    1.
0.76    14.5    1.
0.76    15.5    1.
0.76    16.5    1.
0.76    17.5    1.
0.76    18.5    1.
0.8 0.5 0.
0.8 1.5 0.00175
0.8 2.5 0.7495
0.8 3.5 1.
0.8 4.5 1.
0.8 5.5 1.
0.8 6.5 1.
0.8 7.5 1.
0.8 8.5 1.
0.8 9.5 1.
0.8 10.5    1.
0.8 11.5    1.
0.8 12.5    1.
0.8 13.5    1.
0.8 14.5    1.
0.8 15.5    1.
0.8 16.5    1.
0.8 17.5    1.
0.8 18.5    1.
0.84    0.5 0.
0.84    1.5 0.004
0.84    2.5 0.873
0.84    3.5 1.
0.84    4.5 1.
0.84    5.5 1.
0.84    6.5 1.
0.84    7.5 1.
0.84    8.5 1.
0.84    9.5 1.
0.84    10.5    1.
0.84    11.5    1.
0.84    12.5    1.
0.84    13.5    1.
0.84    14.5    1.
0.84    15.5    1.
0.84    16.5    1.
0.84    17.5    1.
0.84    18.5    1.
0.88    0.5 0.
0.88    1.5 0.01825
0.88    2.5 0.94325
0.88    3.5 1.
0.88    4.5 1.
0.88    5.5 1.
0.88    6.5 1.
0.88    7.5 1.
0.88    8.5 1.
0.88    9.5 1.
0.88    10.5    1.
0.88    11.5    1.
0.88    12.5    1.
0.88    13.5    1.
0.88    14.5    1.
0.88    15.5    1.
0.88    16.5    1.
0.88    17.5    1.
0.88    18.5    1.
0.92    0.5 0.
0.92    1.5 0.07
0.92    2.5 0.988
0.92    3.5 1.
0.92    4.5 1.
0.92    5.5 1.
0.92    6.5 1.
0.92    7.5 1.
0.92    8.5 1.
0.92    9.5 1.
0.92    10.5    1.
0.92    11.5    1.
0.92    12.5    1.
0.92    13.5    1.
0.92    14.5    1.
0.92    15.5    1.
0.92    16.5    1.
0.92    17.5    1.
0.92    18.5    1.
\end{filecontents*}

\begin{document}
\begin{tikzpicture} 
    \begin{axis}[
    xlabel=$x$,
    ylabel=$y$,
    zlabel={$f(x,y) = x\cdot y$},
    title=DFSA,
    small,view={0}{90},colorbar,
]

       \addplot3 [surf,
        % shader=interp,
        patch type=bilinear,
        % mesh/color input=explicit,
        ]
        table {dfsa3c.dat};
    \end{axis}
\end{tikzpicture}
\end{document}

我想要得到这样的情节:

在此处输入图片描述

我想让颜色之间的过渡更平滑一些,或者只是用 TikZ 实现这个图。颜色图并不重要,但选择好的颜色图可能会提高绘图质量。

答案1

如果你不想重组数据文件,你也可以使用其中一个键

  • mesh/cols
  • mesh/rows 具有相应的值,在本例中为19
% used PGFPlots v1.17
\begin{filecontents*}{dfsa3c.dat}
    0.12    0.5 0.
    0.12    1.5 0.
    0.12    2.5 0.
    0.12    3.5 0.
    0.12    4.5 0.
    0.12    5.5 0.
    0.12    6.5 0.
    0.12    7.5 0.
    0.12    8.5 0.
    0.12    9.5 0.
    0.12    10.5    0.
    0.12    11.5    0.
    0.12    12.5    0.
    0.12    13.5    0.
    0.12    14.5    0.
    0.12    15.5    0.
    0.12    16.5    0.
    0.12    17.5    0.
    0.12    18.5    0.
    0.16    0.5 0.
    0.16    1.5 0.
    0.16    2.5 0.
    0.16    3.5 0.
    0.16    4.5 0.
    0.16    5.5 0.
    0.16    6.5 0.
    0.16    7.5 0.
    0.16    8.5 0.
    0.16    9.5 0.
    0.16    10.5    0.
    0.16    11.5    0.
    0.16    12.5    0.
    0.16    13.5    0.
    0.16    14.5    0.
    0.16    15.5    0.
    0.16    16.5    0.
    0.16    17.5    0.
    0.16    18.5    0.
    0.2 0.5 0.
    0.2 1.5 0.
    0.2 2.5 0.
    0.2 3.5 0.
    0.2 4.5 0.
    0.2 5.5 0.
    0.2 6.5 0.
    0.2 7.5 0.
    0.2 8.5 0.
    0.2 9.5 0.
    0.2 10.5    0.
    0.2 11.5    0.
    0.2 12.5    0.
    0.2 13.5    0.
    0.2 14.5    0.
    0.2 15.5    0.
    0.2 16.5    0.
    0.2 17.5    0.
    0.2 18.5    0.
    0.24    0.5 0.
    0.24    1.5 0.
    0.24    2.5 0.
    0.24    3.5 0.
    0.24    4.5 0.
    0.24    5.5 0.
    0.24    6.5 0.
    0.24    7.5 0.
    0.24    8.5 0.
    0.24    9.5 0.012333333333333333
    0.24    10.5    0.101
    0.24    11.5    0.2747278202455409
    0.24    12.5    0.46103719793646486
    0.24    13.5    0.5046684223126646
    0.24    14.5    0.483661499790532
    0.24    15.5    0.5092097445038621
    0.24    16.5    0.5
    0.24    17.5    0.5021666666666667
    0.24    18.5    0.506
    0.28    0.5 0.
    0.28    1.5 0.
    0.28    2.5 0.
    0.28    3.5 0.
    0.28    4.5 0.
    0.28    5.5 0.
    0.28    6.5 0.0006666666666666666
    0.28    7.5 0.035
    0.28    8.5 0.4125
    0.28    9.5 0.9543333333333334
    0.28    10.5    1.
    0.28    11.5    1.
    0.28    12.5    1.
    0.28    13.5    1.
    0.28    14.5    1.
    0.28    15.5    1.
    0.28    16.5    1.
    0.28    17.5    1.
    0.28    18.5    1.
    0.32    0.5 0.
    0.32    1.5 0.
    0.32    2.5 0.
    0.32    3.5 0.
    0.32    4.5 0.
    0.32    5.5 0.00525
    0.32    6.5 0.4053333333333333
    0.32    7.5 0.907
    0.32    8.5 0.996
    0.32    9.5 1.
    0.32    10.5    1.
    0.32    11.5    1.
    0.32    12.5    1.
    0.32    13.5    1.
    0.32    14.5    1.
    0.32    15.5    1.
    0.32    16.5    1.
    0.32    17.5    1.
    0.32    18.5    1.
    0.36    0.5 0.
    0.36    1.5 0.
    0.36    2.5 0.
    0.36    3.5 0.
    0.36    4.5 0.
    0.36    5.5 0.1665
    0.36    6.5 0.9516666666666667
    0.36    7.5 1.
    0.36    8.5 1.
    0.36    9.5 1.
    0.36    10.5    1.
    0.36    11.5    1.
    0.36    12.5    1.
    0.36    13.5    1.
    0.36    14.5    1.
    0.36    15.5    1.
    0.36    16.5    1.
    0.36    17.5    1.
    0.36    18.5    1.
    0.4 0.5 0.
    0.4 1.5 0.
    0.4 2.5 0.
    0.4 3.5 0.0007524454477050414
    0.4 4.5 0.07252856433184302
    0.4 5.5 0.71425
    0.4 6.5 0.9996666666666667
    0.4 7.5 1.
    0.4 8.5 1.
    0.4 9.5 1.
    0.4 10.5    1.
    0.4 11.5    1.
    0.4 12.5    1.
    0.4 13.5    1.
    0.4 14.5    1.
    0.4 15.5    1.
    0.4 16.5    1.
    0.4 17.5    1.
    0.4 18.5    1.
    0.44    0.5 0.
    0.44    1.5 0.
    0.44    2.5 0.
    0.44    3.5 0.013
    0.44    4.5 0.489
    0.44    5.5 0.988
    0.44    6.5 1.
    0.44    7.5 1.
    0.44    8.5 1.
    0.44    9.5 1.
    0.44    10.5    1.
    0.44    11.5    1.
    0.44    12.5    1.
    0.44    13.5    1.
    0.44    14.5    1.
    0.44    15.5    1.
    0.44    16.5    1.
    0.44    17.5    1.
    0.44    18.5    1.
    0.48    0.5 0.
    0.48    1.5 0.
    0.48    2.5 0.
    0.48    3.5 0.1725
    0.48    4.5 0.9245
    0.48    5.5 0.99925
    0.48    6.5 1.
    0.48    7.5 1.
    0.48    8.5 1.
    0.48    9.5 1.
    0.48    10.5    1.
    0.48    11.5    1.
    0.48    12.5    1.
    0.48    13.5    1.
    0.48    14.5    1.
    0.48    15.5    1.
    0.48    16.5    1.
    0.48    17.5    1.
    0.48    18.5    1.
    0.52    0.5 0.
    0.52    1.5 0.
    0.52    2.5 0.001
    0.52    3.5 0.522
    0.52    4.5 1.
    0.52    5.5 1.
    0.52    6.5 1.
    0.52    7.5 1.
    0.52    8.5 1.
    0.52    9.5 1.
    0.52    10.5    1.
    0.52    11.5    1.
    0.52    12.5    1.
    0.52    13.5    1.
    0.52    14.5    1.
    0.52    15.5    1.
    0.52    16.5    1.
    0.52    17.5    1.
    0.52    18.5    1.
    0.56    0.5 0.
    0.56    1.5 0.
    0.56    2.5 0.0045
    0.56    3.5 0.758137205808713
    0.56    4.5 0.9990029910269193
    0.56    5.5 1.
    0.56    6.5 1.
    0.56    7.5 1.
    0.56    8.5 1.
    0.56    9.5 1.
    0.56    10.5    1.
    0.56    11.5    1.
    0.56    12.5    1.
    0.56    13.5    1.
    0.56    14.5    1.
    0.56    15.5    1.
    0.56    16.5    1.
    0.56    17.5    1.
    0.56    18.5    1.
    0.6 0.5 0.
    0.6 1.5 0.
    0.6 2.5 0.055
    0.6 3.5 0.927122464312547
    0.6 4.5 1.
    0.6 5.5 1.
    0.6 6.5 1.
    0.6 7.5 1.
    0.6 8.5 1.
    0.6 9.5 1.
    0.6 10.5    1.
    0.6 11.5    1.
    0.6 12.5    1.
    0.6 13.5    1.
    0.6 14.5    1.
    0.6 15.5    1.
    0.6 16.5    1.
    0.6 17.5    1.
    0.6 18.5    1.
    0.64    0.5 0.
    0.64    1.5 0.
    0.64    2.5 0.2115
    0.64    3.5 0.9932364729458918
    0.64    4.5 1.
    0.64    5.5 1.
    0.64    6.5 1.
    0.64    7.5 1.
    0.64    8.5 1.
    0.64    9.5 1.
    0.64    10.5    1.
    0.64    11.5    1.
    0.64    12.5    1.
    0.64    13.5    1.
    0.64    14.5    1.
    0.64    15.5    1.
    0.64    16.5    1.
    0.64    17.5    1.
    0.64    18.5    1.
    0.68    0.5 0.
    0.68    1.5 0.
    0.68    2.5 0.384
    0.68    3.5 0.999498997995992
    0.68    4.5 1.
    0.68    5.5 1.
    0.68    6.5 1.
    0.68    7.5 1.
    0.68    8.5 1.
    0.68    9.5 1.
    0.68    10.5    1.
    0.68    11.5    1.
    0.68    12.5    1.
    0.68    13.5    1.
    0.68    14.5    1.
    0.68    15.5    1.
    0.68    16.5    1.
    0.68    17.5    1.
    0.68    18.5    1.
    0.72    0.5 0.
    0.72    1.5 0.
    0.72    2.5 0.5045
    0.72    3.5 1.
    0.72    4.5 1.
    0.72    5.5 1.
    0.72    6.5 1.
    0.72    7.5 1.
    0.72    8.5 1.
    0.72    9.5 1.
    0.72    10.5    1.
    0.72    11.5    1.
    0.72    12.5    1.
    0.72    13.5    1.
    0.72    14.5    1.
    0.72    15.5    1.
    0.72    16.5    1.
    0.72    17.5    1.
    0.72    18.5    1.
    0.76    0.5 0.
    0.76    1.5 0.0005
    0.76    2.5 0.6215
    0.76    3.5 1.
    0.76    4.5 1.
    0.76    5.5 1.
    0.76    6.5 1.
    0.76    7.5 1.
    0.76    8.5 1.
    0.76    9.5 1.
    0.76    10.5    1.
    0.76    11.5    1.
    0.76    12.5    1.
    0.76    13.5    1.
    0.76    14.5    1.
    0.76    15.5    1.
    0.76    16.5    1.
    0.76    17.5    1.
    0.76    18.5    1.
    0.8 0.5 0.
    0.8 1.5 0.00175
    0.8 2.5 0.7495
    0.8 3.5 1.
    0.8 4.5 1.
    0.8 5.5 1.
    0.8 6.5 1.
    0.8 7.5 1.
    0.8 8.5 1.
    0.8 9.5 1.
    0.8 10.5    1.
    0.8 11.5    1.
    0.8 12.5    1.
    0.8 13.5    1.
    0.8 14.5    1.
    0.8 15.5    1.
    0.8 16.5    1.
    0.8 17.5    1.
    0.8 18.5    1.
    0.84    0.5 0.
    0.84    1.5 0.004
    0.84    2.5 0.873
    0.84    3.5 1.
    0.84    4.5 1.
    0.84    5.5 1.
    0.84    6.5 1.
    0.84    7.5 1.
    0.84    8.5 1.
    0.84    9.5 1.
    0.84    10.5    1.
    0.84    11.5    1.
    0.84    12.5    1.
    0.84    13.5    1.
    0.84    14.5    1.
    0.84    15.5    1.
    0.84    16.5    1.
    0.84    17.5    1.
    0.84    18.5    1.
    0.88    0.5 0.
    0.88    1.5 0.01825
    0.88    2.5 0.94325
    0.88    3.5 1.
    0.88    4.5 1.
    0.88    5.5 1.
    0.88    6.5 1.
    0.88    7.5 1.
    0.88    8.5 1.
    0.88    9.5 1.
    0.88    10.5    1.
    0.88    11.5    1.
    0.88    12.5    1.
    0.88    13.5    1.
    0.88    14.5    1.
    0.88    15.5    1.
    0.88    16.5    1.
    0.88    17.5    1.
    0.88    18.5    1.
    0.92    0.5 0.
    0.92    1.5 0.07
    0.92    2.5 0.988
    0.92    3.5 1.
    0.92    4.5 1.
    0.92    5.5 1.
    0.92    6.5 1.
    0.92    7.5 1.
    0.92    8.5 1.
    0.92    9.5 1.
    0.92    10.5    1.
    0.92    11.5    1.
    0.92    12.5    1.
    0.92    13.5    1.
    0.92    14.5    1.
    0.92    15.5    1.
    0.92    16.5    1.
    0.92    17.5    1.
    0.92    18.5    1.
\end{filecontents*}
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
    % (use this `compat` level or higher to make use of the advanced label positioning)
    \pgfplotsset{compat=1.3}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        xlabel=$x$,
        ylabel=$y$,
        zlabel={$f(x,y) = x\cdot y$},
        title=DFSA,
        small,
        view={0}{90},
        colorbar,
    ]
        \addplot3 [
            surf,
%            shader=interp,
            mesh/cols=19,   % <-- added
        ] table {dfsa3c.dat};
    \end{axis}
\end{tikzpicture}
\end{document}

该图显示了上述代码的结果

答案2

如果添加所需的空行,则不会出现错误。

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.15}
\usepgfplotslibrary{patchplots}
\usepackage{filecontents}

\begin{filecontents*}{dfsa3c.dat}
0.12    0.5 0.
0.12    1.5 0.
0.12    2.5 0.
0.12    3.5 0.
0.12    4.5 0.
0.12    5.5 0.
0.12    6.5 0.
0.12    7.5 0.
0.12    8.5 0.
0.12    9.5 0.
0.12    10.5    0.
0.12    11.5    0.
0.12    12.5    0.
0.12    13.5    0.
0.12    14.5    0.
0.12    15.5    0.
0.12    16.5    0.
0.12    17.5    0.
0.12    18.5    0.

0.16    0.5 0.
0.16    1.5 0.
0.16    2.5 0.
0.16    3.5 0.
0.16    4.5 0.
0.16    5.5 0.
0.16    6.5 0.
0.16    7.5 0.
0.16    8.5 0.
0.16    9.5 0.
0.16    10.5    0.
0.16    11.5    0.
0.16    12.5    0.
0.16    13.5    0.
0.16    14.5    0.
0.16    15.5    0.
0.16    16.5    0.
0.16    17.5    0.
0.16    18.5    0.

0.2 0.5 0.
0.2 1.5 0.
0.2 2.5 0.
0.2 3.5 0.
0.2 4.5 0.
0.2 5.5 0.
0.2 6.5 0.
0.2 7.5 0.
0.2 8.5 0.
0.2 9.5 0.
0.2 10.5    0.
0.2 11.5    0.
0.2 12.5    0.
0.2 13.5    0.
0.2 14.5    0.
0.2 15.5    0.
0.2 16.5    0.
0.2 17.5    0.
0.2 18.5    0.

0.24    0.5 0.
0.24    1.5 0.
0.24    2.5 0.
0.24    3.5 0.
0.24    4.5 0.
0.24    5.5 0.
0.24    6.5 0.
0.24    7.5 0.
0.24    8.5 0.
0.24    9.5 0.012333333333333333
0.24    10.5    0.101
0.24    11.5    0.2747278202455409
0.24    12.5    0.46103719793646486
0.24    13.5    0.5046684223126646
0.24    14.5    0.483661499790532
0.24    15.5    0.5092097445038621
0.24    16.5    0.5
0.24    17.5    0.5021666666666667
0.24    18.5    0.506

0.28    0.5 0.
0.28    1.5 0.
0.28    2.5 0.
0.28    3.5 0.
0.28    4.5 0.
0.28    5.5 0.
0.28    6.5 0.0006666666666666666
0.28    7.5 0.035
0.28    8.5 0.4125
0.28    9.5 0.9543333333333334
0.28    10.5    1.
0.28    11.5    1.
0.28    12.5    1.
0.28    13.5    1.
0.28    14.5    1.
0.28    15.5    1.
0.28    16.5    1.
0.28    17.5    1.
0.28    18.5    1.

0.32    0.5 0.
0.32    1.5 0.
0.32    2.5 0.
0.32    3.5 0.
0.32    4.5 0.
0.32    5.5 0.00525
0.32    6.5 0.4053333333333333
0.32    7.5 0.907
0.32    8.5 0.996
0.32    9.5 1.
0.32    10.5    1.
0.32    11.5    1.
0.32    12.5    1.
0.32    13.5    1.
0.32    14.5    1.
0.32    15.5    1.
0.32    16.5    1.
0.32    17.5    1.
0.32    18.5    1.

0.36    0.5 0.
0.36    1.5 0.
0.36    2.5 0.
0.36    3.5 0.
0.36    4.5 0.
0.36    5.5 0.1665
0.36    6.5 0.9516666666666667
0.36    7.5 1.
0.36    8.5 1.
0.36    9.5 1.
0.36    10.5    1.
0.36    11.5    1.
0.36    12.5    1.
0.36    13.5    1.
0.36    14.5    1.
0.36    15.5    1.
0.36    16.5    1.
0.36    17.5    1.
0.36    18.5    1.

0.4 0.5 0.
0.4 1.5 0.
0.4 2.5 0.
0.4 3.5 0.0007524454477050414
0.4 4.5 0.07252856433184302
0.4 5.5 0.71425
0.4 6.5 0.9996666666666667
0.4 7.5 1.
0.4 8.5 1.
0.4 9.5 1.
0.4 10.5    1.
0.4 11.5    1.
0.4 12.5    1.
0.4 13.5    1.
0.4 14.5    1.
0.4 15.5    1.
0.4 16.5    1.
0.4 17.5    1.
0.4 18.5    1.

0.44    0.5 0.
0.44    1.5 0.
0.44    2.5 0.
0.44    3.5 0.013
0.44    4.5 0.489
0.44    5.5 0.988
0.44    6.5 1.
0.44    7.5 1.
0.44    8.5 1.
0.44    9.5 1.
0.44    10.5    1.
0.44    11.5    1.
0.44    12.5    1.
0.44    13.5    1.
0.44    14.5    1.
0.44    15.5    1.
0.44    16.5    1.
0.44    17.5    1.
0.44    18.5    1.

0.48    0.5 0.
0.48    1.5 0.
0.48    2.5 0.
0.48    3.5 0.1725
0.48    4.5 0.9245
0.48    5.5 0.99925
0.48    6.5 1.
0.48    7.5 1.
0.48    8.5 1.
0.48    9.5 1.
0.48    10.5    1.
0.48    11.5    1.
0.48    12.5    1.
0.48    13.5    1.
0.48    14.5    1.
0.48    15.5    1.
0.48    16.5    1.
0.48    17.5    1.
0.48    18.5    1.

0.52    0.5 0.
0.52    1.5 0.
0.52    2.5 0.001
0.52    3.5 0.522
0.52    4.5 1.
0.52    5.5 1.
0.52    6.5 1.
0.52    7.5 1.
0.52    8.5 1.
0.52    9.5 1.
0.52    10.5    1.
0.52    11.5    1.
0.52    12.5    1.
0.52    13.5    1.
0.52    14.5    1.
0.52    15.5    1.
0.52    16.5    1.
0.52    17.5    1.
0.52    18.5    1.

0.56    0.5 0.
0.56    1.5 0.
0.56    2.5 0.0045
0.56    3.5 0.758137205808713
0.56    4.5 0.9990029910269193
0.56    5.5 1.
0.56    6.5 1.
0.56    7.5 1.
0.56    8.5 1.
0.56    9.5 1.
0.56    10.5    1.
0.56    11.5    1.
0.56    12.5    1.
0.56    13.5    1.
0.56    14.5    1.
0.56    15.5    1.
0.56    16.5    1.
0.56    17.5    1.
0.56    18.5    1.

0.6 0.5 0.
0.6 1.5 0.
0.6 2.5 0.055
0.6 3.5 0.927122464312547
0.6 4.5 1.
0.6 5.5 1.
0.6 6.5 1.
0.6 7.5 1.
0.6 8.5 1.
0.6 9.5 1.
0.6 10.5    1.
0.6 11.5    1.
0.6 12.5    1.
0.6 13.5    1.
0.6 14.5    1.
0.6 15.5    1.
0.6 16.5    1.
0.6 17.5    1.
0.6 18.5    1.

0.64    0.5 0.
0.64    1.5 0.
0.64    2.5 0.2115
0.64    3.5 0.9932364729458918
0.64    4.5 1.
0.64    5.5 1.
0.64    6.5 1.
0.64    7.5 1.
0.64    8.5 1.
0.64    9.5 1.
0.64    10.5    1.
0.64    11.5    1.
0.64    12.5    1.
0.64    13.5    1.
0.64    14.5    1.
0.64    15.5    1.
0.64    16.5    1.
0.64    17.5    1.
0.64    18.5    1.

0.68    0.5 0.
0.68    1.5 0.
0.68    2.5 0.384
0.68    3.5 0.999498997995992
0.68    4.5 1.
0.68    5.5 1.
0.68    6.5 1.
0.68    7.5 1.
0.68    8.5 1.
0.68    9.5 1.
0.68    10.5    1.
0.68    11.5    1.
0.68    12.5    1.
0.68    13.5    1.
0.68    14.5    1.
0.68    15.5    1.
0.68    16.5    1.
0.68    17.5    1.
0.68    18.5    1.

0.72    0.5 0.
0.72    1.5 0.
0.72    2.5 0.5045
0.72    3.5 1.
0.72    4.5 1.
0.72    5.5 1.
0.72    6.5 1.
0.72    7.5 1.
0.72    8.5 1.
0.72    9.5 1.
0.72    10.5    1.
0.72    11.5    1.
0.72    12.5    1.
0.72    13.5    1.
0.72    14.5    1.
0.72    15.5    1.
0.72    16.5    1.
0.72    17.5    1.
0.72    18.5    1.

0.76    0.5 0.
0.76    1.5 0.0005
0.76    2.5 0.6215
0.76    3.5 1.
0.76    4.5 1.
0.76    5.5 1.
0.76    6.5 1.
0.76    7.5 1.
0.76    8.5 1.
0.76    9.5 1.
0.76    10.5    1.
0.76    11.5    1.
0.76    12.5    1.
0.76    13.5    1.
0.76    14.5    1.
0.76    15.5    1.
0.76    16.5    1.
0.76    17.5    1.
0.76    18.5    1.

0.8 0.5 0.
0.8 1.5 0.00175
0.8 2.5 0.7495
0.8 3.5 1.
0.8 4.5 1.
0.8 5.5 1.
0.8 6.5 1.
0.8 7.5 1.
0.8 8.5 1.
0.8 9.5 1.
0.8 10.5    1.
0.8 11.5    1.
0.8 12.5    1.
0.8 13.5    1.
0.8 14.5    1.
0.8 15.5    1.
0.8 16.5    1.
0.8 17.5    1.
0.8 18.5    1.

0.84    0.5 0.
0.84    1.5 0.004
0.84    2.5 0.873
0.84    3.5 1.
0.84    4.5 1.
0.84    5.5 1.
0.84    6.5 1.
0.84    7.5 1.
0.84    8.5 1.
0.84    9.5 1.
0.84    10.5    1.
0.84    11.5    1.
0.84    12.5    1.
0.84    13.5    1.
0.84    14.5    1.
0.84    15.5    1.
0.84    16.5    1.
0.84    17.5    1.
0.84    18.5    1.

0.88    0.5 0.
0.88    1.5 0.01825
0.88    2.5 0.94325
0.88    3.5 1.
0.88    4.5 1.
0.88    5.5 1.
0.88    6.5 1.
0.88    7.5 1.
0.88    8.5 1.
0.88    9.5 1.
0.88    10.5    1.
0.88    11.5    1.
0.88    12.5    1.
0.88    13.5    1.
0.88    14.5    1.
0.88    15.5    1.
0.88    16.5    1.
0.88    17.5    1.
0.88    18.5    1.

0.92    0.5 0.
0.92    1.5 0.07
0.92    2.5 0.988
0.92    3.5 1.
0.92    4.5 1.
0.92    5.5 1.
0.92    6.5 1.
0.92    7.5 1.
0.92    8.5 1.
0.92    9.5 1.
0.92    10.5    1.
0.92    11.5    1.
0.92    12.5    1.
0.92    13.5    1.
0.92    14.5    1.
0.92    15.5    1.
0.92    16.5    1.
0.92    17.5    1.
0.92    18.5    1.
\end{filecontents*}

\begin{document}
\centering
\begin{tikzpicture} 
    \begin{axis}[
    xlabel=$x$,
    ylabel=$y$,
    zlabel={$f(x,y) = x\cdot y$},
    title=DFSA,
    small,view={0}{90},colorbar,
]

       \addplot3 [surf,
        % shader=interp,
        patch type=bilinear,
        % mesh/color input=explicit,
        ]
        table {dfsa3c.dat};
    \end{axis}
    \begin{axis}[xshift=8cm,
    xlabel=$x$,
    ylabel=$y$,
     title=DFSA,
    small,view={0}{90},colorbar,
]
       \addplot3 [surf,
        shader=interp,
        ]
        table {dfsa3c.dat};
    \end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容