2

I am trying to use gnuplot within pgfplots to draw contour plots for a data file. The contour curves are unfortunately not smooth enough, and the additional limitation is the size of the data file (a 41 x 41 grid at present). A typical MWE for my code would be:

\documentclass[11pt,tikz]{standalone}
\usepackage{tikz,pgfplots,amsmath,amssymb}

\newlength\figureheight
\setlength{\figureheight}{5cm}
\newlength\figurewidth
\setlength{\figurewidth}{\figureheight}

\pgfplotsset{compat=1.13}

\begin{document}
\begin{tikzpicture}
\begin{axis}[%
height=\figureheight,
width=\figurewidth,
scale only axis,
axis x line*=bottom,
axis y line*=left,
axis z line*=left,
view={0}{90},
xlabel={$x$},
ylabel={$y$},
]%
\addplot3[%
contour gnuplot={%
draw color=black,
levels={0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9},
labels=false,
handler/.style=smooth},
mesh/rows=41,
mesh/cols=42] table[header=false]{datfile.dat};
\end{axis}
\end{tikzpicture}
\end{document}

Using the handler option from PGFPlots manual has not helped in this case. If, however, I use the smooth option in the axis environment, I get zigzag lines throughout the graph.

If there is no way to solve this problem within PGFPlots, I was wondering if there is some other route available by:

1) either calling programs like gnuplot or matlab etc. from within PGFPlots, or

2) using smooth, interpolated contour plots to begin with, through Mathematica or similar.

Any suggestions in either direction, or any better solution, would be helpful and greatly appreciated. Thank you!

EDIT: The contour plot generated from above code contour_plot[2]

Link to data file.

  • Can you make your code complete with the preamble? Just the necessary packages for this code. – Alenanno Mar 5 '16 at 0:22
  • Included preamble and packages used. Would it help to add the datfile.dat too? Thank you. – smike Mar 5 '16 at 13:00
  • If your plot uses that data, yes thanks. You can paste it and then add the code formatting to it. – Alenanno Mar 5 '16 at 13:19
  • I have included the contour plot. Couldn't copy-paste the data file, it was too large for the comments section. I will try to include it on some file hosting site and link here. – smike Mar 5 '16 at 13:41
  • Included the data file too now. – smike Mar 5 '16 at 13:47

Your Answer

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

Browse other questions tagged or ask your own question.