1

I have a 3D object produced from Matlab which is like this: enter image description here

I would like use a vector graphics of the above in my document. However due to the file size, I prefer to save as tikz picture. I used Matlab2tikz for the above picture and got the following one:

enter image description here

I have no concerns about the labels, but can someone help me get the same rendering or a near similar one?

4

1 Answer 1

4

I cannot post the full code due to length constrictions, but this is what I did:

  • removed the first \addplot3
  • removed the fill=white!85!black to see the already existing shading
  • Use a suitable colour scale for the desired shading

\documentclass[tikz]{standalone}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\usepackage{grffile}
\pgfplotsset{compat=newest}
\usetikzlibrary{plotmarks}
\usetikzlibrary{arrows.meta}
\usepgfplotslibrary{patchplots}
\usepackage{amsmath}

\begin{document}
\begin{tikzpicture}
\begin{axis}[%
width=4.895in,
height=5.264in,
at={(4.102in,0.71in)},
scale only axis,
plot box ratio=4 1 1,
xmin=-0.5,
xmax=0.5,
tick align=outside,
ymin=-0.125,
ymax=0.125,
zmin=-0.125,
zmax=0.125,
view={-133.1}{69.2},
axis x line*=bottom,
axis y line*=left,
axis z line*=left
]

\addplot3[%
surf, z buffer=sort, colormap={my}{
    rgb255=(20,20,20) 
    rgb255=(50,50,50) 
    rgb255=(250,250,250)
}, mesh/rows=21]
table[row sep=crcr, point meta=\thisrow{c}] {%
%
x   y   z   c\\
-0.5    0   0   0\\
-0.498461042574392  0   0.0195543081300289  0.0195543081300289\\
-0.493882064536894  0   0.0386271242968684  0.0386271242968684\\
...

enter image description here

5
  • That's a strong progress! Can we do something more about the lighting too?
    – SKPS
    Apr 13, 2018 at 13:05
  • @SathishKrishnan You can change it by selecting a suitable colour palette. Apr 13, 2018 at 13:11
  • @SathishKrishnan You're welcome! Apr 13, 2018 at 13:45
  • Also, please update the code in the pastebin for future users.
    – SKPS
    Apr 13, 2018 at 13:50
  • @SathishKrishnan Ups, I forgot about pastebin. Don't have the code any more. Apr 13, 2018 at 13:52

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.