[Tex/LaTex] 3D surface plots in TikZ


I need to plot a surface plot using TikZ. I have the (x,y) coordinate and the corresponding function value in a table form. I have not done 3D plots before in TikZ and hence I would appreciate any help. I would want a surf plot like this, but I do not have a closed form expression for my function. Instead, I have a table of values as shown below.The (X,Y) values are a two dimensional uniform grid on the domain [0,4] * [0,4].

enter image description here

Best Answer

TikZ cannot do this with builtin methods. pgfplots can do it - in your case with \addplot3[surf, mesh/ordering=x varies] table {myfile.dat}; .

It supports custom colormaps, color bars, draws an appropriate axis, chooses suitable scales, ticks, and ticklabels etc.

See http://pgfplots.sourceforge.net/pgfplots.pdf for details and examples.

By default, pgfplots assumes numerical input (i.e. 0.29 instead of 29/10). If your data file really looks like

0 0 29/10

you need to write \addplot3.... table[z expr=\thisrow{Z}] {myfile.dat}; in order to activate math expression parsing for that column.

Related Question