6

I'm trying to plot a 3d surface using pgfplots and this is what I have done so far:

\usepgfplotslibrary{patchplots}
\begin{tikzpicture}
\begin{axis}[%
width=12cm,height=12cm,
xlabel={$J_1$},
ylabel={$J_2$},
zlabel={$J_3$},
legend style={at={(-0.2,0.14)},anchor=north west,draw=black,fill=white,legend cell align=left},
label style={font=\scriptsize}, ticklabel style={font=\scriptsize}
]

\addplot3[patch,patch type=triangle quadr,opacity = 0.2,
    shader=faceted interp]
coordinates {
  (349.9671,  349.9671,  195.8676)
  (195.8676,  349.9671,  349.9671)
  (349.9671,  195.8676,  349.9671)
  (226.6197,  330.3199,  226.6197)
  (226.6197,  226.6197,  330.3199)
  (330.3199,  226.6197,  226.6197)};
% \addlegendentry{Pareto Front};

\end{axis}
\end{tikzpicture}

enter image description here

I need it in a single color (and it is not), I can't add a legend and I want to change the point of view rotating it. Any advice? Thanks.

juliohm
  • 3,452
Simon
  • 517
  • 5
  • 22

1 Answers1

8
  1. You can choose an appropriate colormap. For example, colormap/gray after loading the colormaps pgfplotslibrary.

  2. You have view={<angle>}{<angle>} or view/h=<angle> and some other commands affecting the view angles. Please refer to the package documentation (Section 4.11.1 View Configuration).

  3. There seems to be an incompatibility between \addlegendentry and patch type=triangle quadr. According a comment from the package author this seems to be a bug; he also suggests adding area legend,fill=black to the plot to get a suitable substitute.

The code:

\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{patchplots,colormaps}
\pgfplotsset{compat=1.9} 
\begin{document}

\begin{tikzpicture}
\begin{axis}[%
width=12cm,height=12cm,
xlabel={$J_1$},
ylabel={$J_2$},
zlabel={$J_3$},
legend style={
  at={(-0.2,0.14)},
  anchor=north west,
  draw=black,
  fill=white,
  legend cell align=left
  },
label style={font=\scriptsize},
ticklabel style={font=\scriptsize},
view={10}{10},
]

\addplot3[
  patch,
  patch type=triangle quadr,
  opacity = 0.5,
  shader=faceted interp,
  colormap/gray,
  area legend,fill=black
  ]
coordinates {
  (349.9671,  349.9671,  195.8676)
  (195.8676,  349.9671,  349.9671)
  (349.9671,  195.8676,  349.9671)
  (226.6197,  330.3199,  226.6197)
  (226.6197,  226.6197,  330.3199)
  (330.3199,  226.6197,  226.6197)};
  \addlegendentry{Pareto Front};
\end{axis}
\end{tikzpicture}

\end{document}

The output as seen on Acrobat Reader (some viewers (Okular, for example) might produce an incorrect result replacing the continuous shading by small rectangles)

enter image description here

Gonzalo Medina
  • 505,128
  • 2
    It seems as if the legend for this kind of plot is, indeed, broken due to a bug. I accept this as bug report for pgfplots. Perhaps the keys area legend,fill=black can help to get a suitable substitute (when added to the plot). – Christian Feuersänger Mar 20 '14 at 22:46
  • 1
    It is also interesting to note that the viewer created wrong output: the small faceted rectangles are an artifact generated by the viewer. It seems that some viewers replace the continuos shadings by many small rectangles and suffer from the same problem as in http://tex.stackexchange.com/questions/58227/is-there-any-way-to-remove-mesh-lines-completely-in-a-pgfplots-faceted-3d-plot . Acrobat reader renders it correctly – Christian Feuersänger Mar 20 '14 at 22:55
  • @ChristianFeuersänger thanks for your comments and suggestions; in fact, I was going to ping you about the problem with the legend but then I forgot; it's a good thing you saw the post. I also added the right image as shown bt Acrobat Reader. – Gonzalo Medina Mar 20 '14 at 23:15
  • @Simon I've updated my answer with new information that could be of interest for you. – Gonzalo Medina Mar 20 '14 at 23:15
  • @GonzaloMedina Thanks a lot, the trick for legend it's perfect. – Simon Mar 21 '14 at 08:49
  • Note that the bug has been fixed; will become part of the next stable pgfplots (probably 1.11). – Christian Feuersänger May 17 '14 at 18:46