2

I would like to export a surf plot, whose face color is for example green, out of MATLAB R2014a to latex with the aid of matlab2tikz. Unfortunately when i run pdflatex the face color now ranges from red to blue and is not green any more. Is there maybe a possible workaround?

my MATLAB Code:

[X,Y] = meshgrid(-10:0.5:10);
Z = sin(sqrt(X.^2 + Y.^2) + eps)./(sqrt(X.^2 + Y.^2) + eps);
surf(X,Y,Z,'FaceColor','green','EdgeColor','black')
matlab2tikz('face.tikz', 'height', '\figureheight', 'width', '\figurewidth');

my Latex Code:

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}
\begin{figure}
\centering
\newlength\figureheight
\newlength\figurewidth
\setlength\figureheight{8cm}
\setlength\figurewidth{12cm}
\input{face.tikz}
\end{figure}
\end{document}

Many thanks in advance

Stefan

EDIT:

MATLAB produces: MATLAB

Matlab2TikZ produces: Matlab2TikZ

Sorry, I first thought I could solve my problem, if someone can solve the "simple" problem...

0

2 Answers 2

3

If I am not mistaken, you search for a constant color for the faces, right?

In this case, you can provide the fill color using fill=green or just green and edges can be configured by means of faceted color=black.

Here is an example which is independent of your file (since I do not have face.tikz). The necessary changes can be added to your file, however:

enter image description here

\documentclass{standalone}

\usepackage{pgfplots}

\pgfplotsset{compat=1.10}

\begin{document}

\begin{tikzpicture}

\begin{axis}[
    %scaled ticks=false,
]
\addplot3[surf,green,faceted color=black,samples at={-10,-9.5,...,10}]
    {sin(deg(sqrt(x^2 + y^2) + 1e-10))/(deg(sqrt(x^2 + y^2) + 1e-10))};

\end{axis}
\end{tikzpicture}
\end{document}

Note that I added \pgfplotsset{compat=1.10} to fix the compatibility level to some recent revision (1.9 should also do it if you have an older TeX).

Once you integrate it into your .tex file, you should seriously consider to write \newlength... into the preamble, i.e. before \begin{document}. Otherwise you will leak memory (TeX is quite bad at it). Only place \setlength into your figures.

If you decide that a single face color is not what you want, you can use a colormap for the face color combined with faceted color=black, perhaps as in the following example:

enter image description here

\documentclass{standalone}

\usepackage{pgfplots}

\pgfplotsset{compat=1.10}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
    colormap={greenblack}{gray=(0.3) color=(green)},
]

\addplot3[surf,faceted color=black,samples at={-10,-9.5,...,10}]
    {sin(deg(sqrt(x^2 + y^2) + 1e-10))/(deg(sqrt(x^2 + y^2) + 1e-10))};

\end{axis}
\end{tikzpicture}
\end{document}

A color map maps the smallest Z value to the first color in the map and the largest Z value to the largest color in the map. There can be many colors in a color map, these will participate as well. The medium Z value will be mapped to the color in the middle (linear interpolation).

2
  • You are absolutely right. If I add green and faceted color=black to my tikz file everthing works well and looks really, really nice. I actually have added \pgfplotsset{compat=1.10} and written \newlength... into the preamble of my "real" document. Unfortunately I have also "real" problem. Instead of that nice function I only have some points somewhere in the space. I already make use of a colormap for the green/red plane as you can see in the picture in my first edited post. The problem right now is, that the turquoise plane also uses this colormap, instead of using the FaceColor.
    – Stefan
    Commented Jul 16, 2014 at 19:04
  • That is good to hear. In order to address the remaining problems, I would suggest to add the contents of face.tikz file. This would complete the minimal example - without it, it is hard to identify the root cause (this is generally good practise and avoids guessing a unnecessary work) Commented Jul 16, 2014 at 19:09
0

To add the contents of face.tikz file, respectively taking a closer look at this file was the perfect suggestion. I should have thought of that before asking the second time. Sorry for that...

There are two \addplot3 commands.

\addplot3[%
surf,
shader=faceted,
draw=black,
z buffer=sort,
colormap={mymap}{[1pt] rgb(0pt)=(1,0,0); rgb(1pt)=(0,1,0)},
point meta=explicit,
mesh/rows=70]
table[row sep=crcr,header=false,meta index=3] {%
%
-0.254193271955138  4.792   0.581426160480253   0\\
...
-0.257911289045355  4.793   0.579837400860877   1\\
...
\addplot3[%
surf,
opacity=0.5,
shader=faceted interp,
colormap={mymap}{[1pt] rgb(0pt)=(1,0,0); rgb(1pt)=(0,1,0)},
mesh/rows=10]
table[row sep=crcr,header=false] {%
%
-0.25   4.793   0.565534283150811\\
-0.25   4.79416666666667    0.552986932032553\\ ...

All I had to do was to replace these lines

shader=faceted interp,
colormap={mymap}{[1pt] rgb(0pt)=(1,0,0); rgb(1pt)=(0,1,0)},

in the second \addplot3 command by those

green,
faceted color=black,

Thanks very very much Christian Feuersänger for your help!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .