Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
9  
Please provide the data in a plain text rather than an image. –  stalking is prohibited Aug 1 '12 at 19:48

1 Answer 1

up vote 20 down vote accepted

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

X Y Z
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.

share|improve this answer
    
As far as I can tell, if the data supplied is in a file (.dat here), the command fileshould be used instead of table- at least that did the trick for me. I suspect that this is syntax that may have changed since the post was written, and just wanted to add this in case it is helpful to someone else coming across this post. Otherwise, great answer! :) –  Kjetil Sonerud Oct 24 at 13:26
1  
Thanks for the update. In fact, file and table are almost the same and both do the job. \addplot3 table is more powerful and allows a huge degree of customization; but its default is actually the same as \addplot3 file. –  Christian Feuersänger Oct 24 at 21:23
1  
Thanks for the clarification! For some reason, this does not seem to work for me - using table instead of file with a .dat-file as source for the plotting data throws an error. I may very well have done something wrong here, but at least file works like a charm. I must add that pgfplots in general is amazing; thanks for that! :) –  Kjetil Sonerud Oct 27 at 9:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.