I would like to make a contour plot of data that has been saved in a text file that consists of three columns where the columns are x_i, y_i and z_i and some elements z_i are NaN.

I use MikTex 2.9 with WinEdt 8.0. I have installed gnuplot and can invoke gnuplot from the command line. I have correctly enabled a shell espace; I use PDFTeXify to compile the document. See the figures below.

call gnuplot from command line execution modes PDFTexiFY

Section 4.6.8 of the pgfplots manual concerns contour plots, but does not discuss using data of the form (x_i,y_i,z_i). I try to use the same method as described in Section 3.5.1 for making a surface plot of data.

Below is my MWE. My data.txt file can be found here.


\pgfplotsset{compat = 1.8}


 \addplot3[contour gnuplot = {labels = false}, 
           mesh/ordering = y varies, 
           mesh/rows = 6, 
           mesh/cols = 16] 
           file {data.txt};


This does not work however. If I change the NaN values in the data file to 0, it works and produces a contour plot. Normally I would use the option unbounded coords = jump, but that does not work here.

How do I ensure that gnuplot works around the NaN values so that the current output if I use zeroes instead of NaN (first figure), looks more like the Matlab output (second figure, which uses the NaN entries). Essentially this means that all lines to the left of the green line I drew in Paint (first figure again) should be discarded and this area should become a no go area.

contour generated by gnuplot contour generated by Matlab


Try gnuplot 5.0 rc 1

Changes in 5.0 include:

* CHANGE Revised handling of NaN in input data stream

I have no errors using NaN values for my contour plots with gnuplot 5.0 rc1

  • Thank you for the answer. When I download gnuplot 5.0 rc 1 in .tar.gz format from this sourceforge, what location do I unzip it to? Also, there does not seem to be an installer? I already have gnuplot 4.6 installed. – Ritz Sep 17 '14 at 7:20
  • 1
    @Ritz You can use the binary from tatsuromatsuoka.com/gnuplot/Eng/winbin – John Sep 17 '14 at 8:50
  • 1
    @Ritz Try this link ctan.ijs.si/mirror/w32tex/w32 These work for me. – John Sep 17 '14 at 13:08
  • 1
    @Ritz I'd try that, yes. – John Sep 17 '14 at 13:55
  • 1
    NaN values are definnitely no problem for gnuplot 5.0 rc 1, see e.g. dropbox.com/s/4hxnmz71b3zd0h4/gnuplot50rc1.png?dl=0 - the white half of the plot are NaN values. Consequently you could use gnuplottex with the commands set pm3d at b set contour base set view map splot 'data.txt' (Used to generate the image shown) – John Sep 17 '14 at 14:28

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.