Following this answer, I have a data file P.dat
which I need to plot it as a filled contour plot.
However, I got this error
Package pgfplots Error: CRITICAL: shader=interp: got unsupported pdf
shading type '0'. This may corrupt your pdf!. \end{axis}
I would be grateful if I could know the error source and how I can make the output match the MATLAB desired one.
P.dat
MWE
\RequirePackage{luatex85}
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot3[contour filled] table {P.dat};
\end{axis}
\end{tikzpicture}
\end{document}
MATLAB Desired Output
Update 1
I made another data file with NaN
z values to account for the void data (white space) and specified the number of rows and columns, but I got this undesired output.
P2.dat
MWE 2
\RequirePackage{luatex85}
\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{patchplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[view={0}{90}]
\addplot3[contour filled,mesh/rows=31,mesh/cols=11,mesh/check=false] table {P2.dat};
\end{axis}
\end{tikzpicture}
\end{document}
Output 2
Update 2
Recalling my raw MATLAB data, how can I remove all the points whose z
values equal to or exceed 1723
in order to get an output similar to my desired one?
P3.dat
MWE 3
\RequirePackage{luatex85}
\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{patchplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[view={0}{90},colorbar, point meta max=1723, point meta min=300,]
\addplot3[contour filled={number = 25,labels={false}},mesh/rows=31,mesh/cols=11,mesh/check=false
] table {P3.dat};
\end{axis}
\end{tikzpicture}
\end{document}
Best Answer
Here I present two solutions.
Solution 1 (left part of the image)
This tries to reproduce the Matlab figure with the capabilities of PGFPlots. To "confirm" that I did it right, I first saved your Matlab image and cropped the axis parts. Then I added this as
\addplot graphics
and on top of that I added the real plot, i.e.\addplot contour filled
plot in 50% transparent. That allowed to check, if I found the interval boundaries right.Said that I think your above statement is wrong. It seems that you removed the color for all values >1600. This also makes sense, because the maximum value in the
P3.dat
file is 1723 ...Solution 2 (right part of the image)
Here I just used the above cropped Matlab image and reproduced the colorbar.
Comparison
As you can see in solution 1 there are some "artifacts" which don't make the result as smooth as the Matlab result. That is, because the contours calculation/visualization only depends on the features of your PDF viewer. Said that it could be that your result differs from mine. I made the screenshot from a view in Acrobat Reader XI.
That is why I favor solution 2.
To improve the result you should modify your Matlab view to only show the contours, that means remove the axis and the grid lines. Then the only difference could be the colors used/shown in Matlab contour plot and the colorbar calculated by PGFPlots. Concrete I mean that one could use RGB colors and the other CMYK. But since you have the illustrator as you said, you could check for that and adapt one of the both parts, i.e. the Matlab or PGFPlots output.
You could also create a "pure", that means also without any axis, version of the colorbar in Matlab and also import this graphics into the PGFPlots colorbar. Of course then colors are identical.
For more details on how the solutions work, please have a look at the comments in the code.