[Tex/LaTex] Matlab2Tikz colorbar / colormap issues

matlab2tikz

I've got some issues using the matlab2tikz script by Nico Schlömer.
In Matlab I created a 3d plot including a bunch of patches. Some scalar values are highlighted using the jet colormap (see the attached *.png file).

Matlab figure

I then translated this figure into a tikzpicture by invoking matlab2tikz('Test6.tex'). Matlab printed the information

> Found colormap/jet to be a pretty good match for your color map (||diff||=0.0280337).

Compiling the rather huge tikz file by

\usetikzlibrary{external} \tikzset{external/system call={lualatex
    \tikzexternalcheckshellescape -halt-on-error
    -interaction=batchmode -jobname "\image" "\texsource"}}
\tikzexternalize[prefix=autofigs/]

and

\begin{figure}[h]
\input{Bilder/Test6.tex}%
\caption{\label{fig:1}Our figure}
\end{figure}

using pdflatex produces this results (screenshot of corresponding pdf)

[Resulting output[2]

Both, the colormap and the colorbar are obviously completely different to the original plot.
Can anyone help me fixing this issue?

Best Answer

I experienced the same issue. I think there is an error in the generation of the colormap in the matlab2tikz.m file. You will have to change some things in your Test6.tex file:

In your tex file there should be the following lines:

point meta min=...,
point meta max=...,

With on the dots your values. This limits the colours of your colormap. These two lines needs to be removed. After doing this already a plot should be generated with the right color values but the colorbar definition will still wrong in order to fix this, the next code block

colormap={mymap}{[1pt] ...}

needs to be placed after

colormap={patchmap}{[1pt] ...}

This will fix the colorbar. But still the tickvalues of the colorbar will be off. This can be fixed manually by using:

colorbar style={        
    ytick={...},
    yticklabels={...}
    }

If it is not completely clear I can make the changes in your file.