1

I have a very special question to all of you Tikz gods out there!

I'm trying to make a plot from 3D data and a view from above. In the end the image should look like a pattern plot with 5 x 5 different tiles, all in a color which corresponds to the z data.

When doing this with the \addplot[surf] function, tikz only outputs a 4 x 4 grid

\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[view={0}{90},
    scale only axis,
    height=5cm,
    xtick = {-1,-0.5,0,0.5,1},
    colormap/blackwhite,
    colorbar right,
    axis equal image,
    mesh/rows=5,
    %shader=faceted interp,
    %patch type=bilinear,
    colormap/blackwhite,
    colorbar right,
]

\addplot3[surf]  coordinates {
(1, 1, 0.28)
(0.5, 1, 0.29)
(0, 1, 0.29)
(-0.5, 1, 0.25)
(-1, 1, 0.26)
(1, 0.5, 0.27)
(0.5, 0.5, 0.28)
(0, 0.5, 0.29)
(-0.5, 0.5, 0.29)
(-1, 0.5, 0.28)
(1, 0, 0.29)
(0.5, 0, 0.25)
(0, 0, 0.27)
(-0.5, 0, 0.25)
(-1, 0, 0.28)
(1, -0.5, 0.25)
(0.5, -0.5, 0.27)
(0, -0.5, 0.28)
(-0.5, -0.5, 0.29)
(-1, -0.5, 0.25)
(1, -1, 0.25)
(0.5, -1, 0.26)
(0, -1, 0.25)
(-0.5, -1, 0.28)
(-1, -1, 0.28)
};

\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

...And this is the closest that i can get with cheating:-/

\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[view={0}{90},
    scale only axis,
    height=5cm,
    xtick = {-1,-0.5,0,0.5,1},
    colormap/blackwhite,
    colorbar right,
    axis equal image,
    enlarge x limits=0.2,
    enlarge y limits=0.2,
]

\addplot3[mesh,scatter,mark=square*,mark size=14,black]  coordinates {
(1, 1, 0.28)
(0.5, 1, 0.29)
(0, 1, 0.29)
(-0.5, 1, 0.25)
(-1, 1, 0.26)
(1, 0.5, 0.27)
(0.5, 0.5, 0.28)
(0, 0.5, 0.29)
(-0.5, 0.5, 0.29)
(-1, 0.5, 0.28)
(1, 0, 0.29)
(0.5, 0, 0.25)
(0, 0, 0.27)
(-0.5, 0, 0.25)
(-1, 0, 0.28)
(1, -0.5, 0.25)
(0.5, -0.5, 0.27)
(0, -0.5, 0.28)
(-0.5, -0.5, 0.29)
(-1, -0.5, 0.25)
(1, -1, 0.25)
(0.5, -1, 0.26)
(0, -1, 0.25)
(-0.5, -1, 0.28)
(-1, -1, 0.28)
};
\end{axis}
\end{tikzpicture}
\end{document}

using markers

There must be any hidden feature, which allows me to do this cleanly with the surf function, right?

Thanks for reading this tldr post!

2

I believe matrix plot is what you want

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\begin{document}
    \begin{tikzpicture}
        \begin{axis}[colormap/blackwhite,colorbar right]
            \addplot[matrix plot,mesh/cols=5,point meta=explicit]table[meta=z]{
                x       y       z
                1       1       0.28
                0.5     1       0.29
                0       1       0.29
                -0.5    1       0.25
                -1      1       0.26
                1       0.5     0.27
                0.5     0.5     0.28
                0       0.5     0.29
                -0.5    0.5     0.29
                -1      0.5     0.28
                1       0       0.29
                0.5     0       0.25
                0       0       0.27
                -0.5    0       0.25
                -1      0       0.28
                1       -0.5    0.25
                0.5     -0.5    0.27
                0       -0.5    0.28
                -0.5    -0.5    0.29
                -1      -0.5    0.25
                1       -1      0.25
                0.5     -1      0.26
                0       -1      0.25
                -0.5    -1      0.28
                -1      -1      0.28
            };
        \end{axis}
    \end{tikzpicture}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.