3

I would like to make a heatmap or density plot from data in a file, using interpolation. I have been testing different options of the pgfplots manual (Section 4.6.7 Surface Plots with Explicit Color), but I do not reach a solution.

For example, the following gives me compile errors:

\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}

I would like to get a plot like this:

enter image description here

I would like to make the transition between colors a little smoother or just achieve this plot with TikZ. The colormap is not important but it is probably that a good colormap selection improves the plot quality.

user1993416
  • 1,046

2 Answers2

7

There are no errors if you add the required empty lines.

\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}

enter image description here

  • Thank you. Is it possible to uncomment shader=interp?. I would like to make a smooth transition between color levels. – user1993416 Apr 03 '19 at 14:01
  • @user1993416 Yes. I added an example of that type, too. –  Apr 03 '19 at 14:03
  • @marmot didnt notice your answer :) +1 – Raaja_is_at_topanswers.xyz Apr 03 '19 at 14:04
  • 1
    Marmot Your too darn quick I got a result four mins ago but am hung up on the poor quality in another viewer. –  Apr 03 '19 at 14:05
  • @Raaja Thanks and sorry, I didn't know you are working on this. –  Apr 03 '19 at 14:05
  • @marmot No no not an issue ;) but a tidy answer :D (off-topic) how did you so quickly made line-spaces at the exact location? which editor do you use? – Raaja_is_at_topanswers.xyz Apr 03 '19 at 14:06
  • @marmot Thank you. I think that shader=interp has a conflict with the other addplot3options. Do you know an easy form to plot some isolines of the Z values in the plot with the interp option? – user1993416 Apr 03 '19 at 14:07
  • @user1993416 Yes, e.g. by using a contour plot, e.g. \addplot3 [contour gnuplot] table {dfsa3c.dat};. Of course you can play with the options (and you need to run with -shell-escape. (And I do not know which conflict you are referring to.) –  Apr 03 '19 at 14:11
  • for what its worth I had rendering problems with differing qualities per viewer Acrobat and Edge producing best results and when printed from acrobat to pdf the quality was then consistently good (better) across all viewers such as firefox sumatrapdf etc. Thus I suspect the result needed some "flattening" –  Apr 03 '19 at 14:21
  • @marmot It seems the shader=interp makes the plot too blurry. Is there any option to make the plot clearer?. I would like the plot to show different colors for each level Z but in both result plots, the change from the Z=0 to Z= 1 does not show much color rage. Is there any way to improve it?. Also, I have tried \addplot3 [contour gnuplot] table {dfsa3c.dat}; but it only plots the isolines. – user1993416 Apr 03 '19 at 14:25
  • @user1993416 You asked "Do you know an easy form to plot some isolines of the Z values in the plot with the interp option?", so I was under the impression that the suggestion to use a contour plot makes sense. Can you tell me in more detail what you want to achieve? What precisely does "improve it" mean? –  Apr 03 '19 at 14:31
  • @marmot I have tried the different shaders but it does not improve much. – user1993416 Apr 03 '19 at 14:31
  • @marmot I am posting an example in the question that I made with Matlab. The plot shows the many Z levels but I would like to control the transition between colors and to plot it with TikZ. – user1993416 Apr 03 '19 at 14:33
  • @marmot In the Matlab plot the zones with the same color (Z's) is variable and separated by lines. – user1993416 Apr 03 '19 at 14:46
  • @user1993416 You had a question which I think I answered. So far you did not even bother to upvote the answer, but only keep adding more requests. If you are so happy with the MatLab plot, why aren't you just using it? (I am not saying that one cannot do that with pgfplots, rather I suspect on can using a filled contour plot and dialing an appropriate point meta, but I regret to tell you that I am out here because I am afraid to be trapped in this thread forever. So if you feel that this answers your original question, accept this answer, or let it be.) –  Apr 03 '19 at 15:01
  • 1
    @marmot I am sorry. Of course, the question is answered from the beginning, but I just forgot to mark it. I am sorry. I will post another to try to get to a similar plot of the example. Matlab is right making computations but as other math environments, it is bad making plots for a publication. – user1993416 Apr 03 '19 at 15:08
  • @KJO I am sorry, when you wrote your comment I didn't really know what you were talking about. After reading p. 162 of the pgfplots manual, I know better. Really sorry! –  Apr 04 '19 at 02:44
  • My apologies for not reading any manuals but yes current p162 shows the effects really well as all I see is a speckled field without any graduation unless I know to reload that page to acrobat which I normally only use for imbedded 3d so interesting for that page to mention viewers such as evince and others having issues without an alternative flatter colour option to fall back to. Thanks for the heads up –  Apr 04 '19 at 03:00
3

If you don't want to restructure the data file you can also use one of the keys

  • mesh/cols
  • mesh/rows with a corresponding value, in this case 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}

image showing the result of above code

Stefan Pinnow
  • 29,535