9

I have been trying to create a surface plot but I am unable to get it to work. Any help would be greatly appreciated. I've tried using surf which only produces lines instead of a surface (Fig. 1). Note: Although I was originally able to produce output, thesurf plot no longer compiles: "Package tikz Error". I've tried compiling with both pdflatex and lualatex with -shell-escape flag.

enter image description here

Figure 1

I also tried to use the patch style plot. This produces gibberish (Fig. 2)

enter image description here

Figure 2

MWE:

\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{external}
\usepgfplotslibrary{patchplots}
\tikzexternalize

\begin{document}
\begin{figure}[t]
  \centering

  \tikzsetnextfilename{surface_plot}
  \begin{tikzpicture}
    \begin{axis} [
      height=12cm,
      width=15cm,
      grid=major,
      grid style={dotted},
      colormap/jet,
      mesh/ordering=x varies
    ]
      %\addplot3[patch,patch type=biquadratic,shader=faceted interp,patch refines=3] coordinates {
      \addplot3[surf] coordinates {

(-6,-6,446.788)  (-5,-6,423.361)  (-4,-6,413.264)  (-3,-6,402.349)  (-2,-6,388.948)  (-1,-6,391.747)  (0,-6,386.874)  (1,-6,423.778)  (2,-6, 439.19)  (3,-6,449.074)  (4,-6,462.155)  (5,-6,484.399)  (6,-6,505.412)
(-6,-5, 423.48)  (-5,-5,392.382)  (-4,-5,406.696)  (-3,-5,392.592)  (-2,-5,371.158)  (-1,-5,384.142)  (0,-5,394.666)  (1,-5,408.105)  (2,-5, 422.51)  (3,-5,420.173)  (4,-5,445.816)  (5,-5,464.731)  (6,-5,485.349)
(-6,-4,402.646)  (-5,-4,371.879)  (-4,-4,376.239)  (-3,-4,396.874)  (-2,-4,382.761)  (-1,-4,386.665)  (0,-4,397.148)  (1,-4,410.875)  (2,-4,425.998)  (3,-4,385.143)  (4,-4,420.458)  (5,-4,438.432)  (6,-4,    458)
(-6,-3,423.219)  (-5,-3,370.582)  (-4,-3,464.786)  (-3,-3,443.921)  (-2,-3,425.196)  (-1,-3,427.138)  (0,-3,438.002)  (1,-3, 453.97)  (2,-3,473.021)  (3,-3,418.583)  (4,-3,435.887)  (5,-3,414.993)  (6,-3,475.148)
(-6,-2,401.995)  (-5,-2,385.612)  (-4,-2,438.956)  (-3,-2,418.583)  (-2,-2,400.093)  (-1,-2,400.773)  (0,-2, 410.58)  (1,-2,426.024)  (2,-2, 444.92)  (3,-2,397.131)  (4,-2,413.739)  (5,-2,431.741)  (6,-2,451.267)
(-6,-1,382.978)  (-5,-1,335.274)  (-4,-1,416.598)  (-3,-1,396.718)  (-2,-1,378.348)  (-1,-1,377.455)  (0,-1,32.0089)  (1,-1,400.683)  (2,-1,419.918)  (3,-1,377.371)  (4,-1,393.286)  (5,-1,374.648)  (6,-1,429.077)
(-6, 0,365.902)  (-5, 0,350.965)  (-4, 0,397.527)  (-3, 0, 378.36)  (-2, 0,360.454)  (-1, 0,358.447)  (0, 0,    363)  (1, 0,381.147)  (2, 0,401.177)  (3, 0,362.155)  (4, 0,378.174)  (5, 0,395.513)  (6, 0, 414.34)
(-6, 1,372.511)  (-5, 1,326.945)  (-4, 1,407.215)  (-3, 1,388.646)  (-2, 1,371.945)  (-1, 1,371.003)  (0, 1,380.027)  (1, 1,396.414)  (2, 1,416.602)  (3, 1,374.897)  (4, 1,391.276)  (5, 1, 373.32)  (6, 1,428.284)
(-6, 2,391.149)  (-5, 2,376.191)  (-4, 2,406.941)  (-3, 2,369.633)  (-2, 2,393.583)  (-1, 2,394.184)  (0, 2,404.263)  (1, 2,420.588)  (2, 2,  440.5)  (3, 2,416.631)  (4, 2,374.948)  (5, 2,391.855)  (6, 2,418.511)
(-6, 3,375.967)  (-5, 3,361.698)  (-4, 3,357.421)  (-3, 3,368.273)  (-2, 3,377.106)  (-1, 3,378.664)  (0, 3,369.175)  (1, 3, 382.42)  (2, 3,397.821)  (3, 3,377.942)  (4, 3,384.944)  (5, 3,387.862)  (6, 3,424.429)
(-6, 4,396.478)  (-5, 4,381.554)  (-4, 4,376.162)  (-3, 4,388.843)  (-2, 4,375.881)  (-1, 4,378.384)  (0, 4, 355.14)  (1, 4,403.654)  (2, 4,419.779)  (3, 4,398.599)  (4, 4,407.113)  (5, 4,426.715)  (6, 4,448.245)
(-6, 5,409.364)  (-5, 5,380.492)  (-4, 5,387.843)  (-3, 5,360.034)  (-2, 5, 362.23)  (-1, 5,364.909)  (0, 5,358.321)  (1, 5,363.226)  (2, 5,379.325)  (3, 5,397.152)  (4, 5,410.086)  (5, 5,433.909)  (6, 5,460.548)
(-6, 6, 423.99)  (-5, 6,408.967)  (-4, 6,400.475)  (-3, 6,372.922)  (-2, 6,371.116)  (-1, 6, 373.92)  (0, 6,384.778)  (1, 6,  398.8)  (2, 6, 415.62)  (3, 6,420.127)  (4, 6,436.064)  (5, 6,461.957)  (6, 6,491.123)

      };
    \end{axis}
  \end{tikzpicture}     
\end{figure}
\end{document}

Thank you so much.

1
  • 1
    I recommend switching to table format instead coordinates.
    – percusse
    Jun 28 '14 at 19:08
9

PGFPlots needs to know how many coordinates are in each row of data. With the formatting you're currently using, it can't infer this information, since it only sees one long line of coordinates (the line breaks aren't enough to break the sequence).

To make the plot work correctly, you can either

  • set mesh/cols=13
  • set mesh/rows=13
  • add an empty line after the first line of data

\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{external}
\usepgfplotslibrary{patchplots}
\tikzexternalize

\begin{document}
\begin{figure}[t]
  \centering

  \tikzsetnextfilename{surface_plot}
  \begin{tikzpicture}
    \begin{axis} [
      height=12cm,
      width=15cm,
      grid=major,
      grid style={dotted},
      colormap/jet,
      mesh/ordering=x varies,
      mesh/cols=13
    ]
      \addplot3[surf] coordinates {
(-6,-6,446.788)  (-5,-6,423.361)  (-4,-6,413.264)  (-3,-6,402.349)  (-2,-6,388.948)  (-1,-6,391.747)  (0,-6,386.874)  (1,-6,423.778)  (2,-6, 439.19)  (3,-6,449.074)  (4,-6,462.155)  (5,-6,484.399)  (6,-6,505.412)
(-6,-5, 423.48)  (-5,-5,392.382)  (-4,-5,406.696)  (-3,-5,392.592)  (-2,-5,371.158)  (-1,-5,384.142)  (0,-5,394.666)  (1,-5,408.105)  (2,-5, 422.51)  (3,-5,420.173)  (4,-5,445.816)  (5,-5,464.731)  (6,-5,485.349)
(-6,-4,402.646)  (-5,-4,371.879)  (-4,-4,376.239)  (-3,-4,396.874)  (-2,-4,382.761)  (-1,-4,386.665)  (0,-4,397.148)  (1,-4,410.875)  (2,-4,425.998)  (3,-4,385.143)  (4,-4,420.458)  (5,-4,438.432)  (6,-4,    458)
(-6,-3,423.219)  (-5,-3,370.582)  (-4,-3,464.786)  (-3,-3,443.921)  (-2,-3,425.196)  (-1,-3,427.138)  (0,-3,438.002)  (1,-3, 453.97)  (2,-3,473.021)  (3,-3,418.583)  (4,-3,435.887)  (5,-3,414.993)  (6,-3,475.148)
(-6,-2,401.995)  (-5,-2,385.612)  (-4,-2,438.956)  (-3,-2,418.583)  (-2,-2,400.093)  (-1,-2,400.773)  (0,-2, 410.58)  (1,-2,426.024)  (2,-2, 444.92)  (3,-2,397.131)  (4,-2,413.739)  (5,-2,431.741)  (6,-2,451.267)
(-6,-1,382.978)  (-5,-1,335.274)  (-4,-1,416.598)  (-3,-1,396.718)  (-2,-1,378.348)  (-1,-1,377.455)  (0,-1,32.0089)  (1,-1,400.683)  (2,-1,419.918)  (3,-1,377.371)  (4,-1,393.286)  (5,-1,374.648)  (6,-1,429.077)
(-6, 0,365.902)  (-5, 0,350.965)  (-4, 0,397.527)  (-3, 0, 378.36)  (-2, 0,360.454)  (-1, 0,358.447)  (0, 0,    363)  (1, 0,381.147)  (2, 0,401.177)  (3, 0,362.155)  (4, 0,378.174)  (5, 0,395.513)  (6, 0, 414.34)
(-6, 1,372.511)  (-5, 1,326.945)  (-4, 1,407.215)  (-3, 1,388.646)  (-2, 1,371.945)  (-1, 1,371.003)  (0, 1,380.027)  (1, 1,396.414)  (2, 1,416.602)  (3, 1,374.897)  (4, 1,391.276)  (5, 1, 373.32)  (6, 1,428.284)
(-6, 2,391.149)  (-5, 2,376.191)  (-4, 2,406.941)  (-3, 2,369.633)  (-2, 2,393.583)  (-1, 2,394.184)  (0, 2,404.263)  (1, 2,420.588)  (2, 2,  440.5)  (3, 2,416.631)  (4, 2,374.948)  (5, 2,391.855)  (6, 2,418.511)
(-6, 3,375.967)  (-5, 3,361.698)  (-4, 3,357.421)  (-3, 3,368.273)  (-2, 3,377.106)  (-1, 3,378.664)  (0, 3,369.175)  (1, 3, 382.42)  (2, 3,397.821)  (3, 3,377.942)  (4, 3,384.944)  (5, 3,387.862)  (6, 3,424.429)
(-6, 4,396.478)  (-5, 4,381.554)  (-4, 4,376.162)  (-3, 4,388.843)  (-2, 4,375.881)  (-1, 4,378.384)  (0, 4, 355.14)  (1, 4,403.654)  (2, 4,419.779)  (3, 4,398.599)  (4, 4,407.113)  (5, 4,426.715)  (6, 4,448.245)
(-6, 5,409.364)  (-5, 5,380.492)  (-4, 5,387.843)  (-3, 5,360.034)  (-2, 5, 362.23)  (-1, 5,364.909)  (0, 5,358.321)  (1, 5,363.226)  (2, 5,379.325)  (3, 5,397.152)  (4, 5,410.086)  (5, 5,433.909)  (6, 5,460.548)
(-6, 6, 423.99)  (-5, 6,408.967)  (-4, 6,400.475)  (-3, 6,372.922)  (-2, 6,371.116)  (-1, 6, 373.92)  (0, 6,384.778)  (1, 6,  398.8)  (2, 6, 415.62)  (3, 6,420.127)  (4, 6,436.064)  (5, 6,461.957)  (6, 6,491.123)

      };
    \end{axis}
  \end{tikzpicture}     
\end{figure}
\end{document}
0

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.