3

I used matlab2tikz to convert a figure from matlab to tikz. When I run this code, I get this addition $.10^-2$ in both X and Y axis. (see figure below ). In addition ytick of the colorbar is also not showing. Can anyone identify cause of the problems, and suggest me the solution.

enter image description here

Here is the code:

  \documentclass{article}
  \usepackage {tikz,pgfplots}
  \usepgfplotslibrary{colormaps}

  \begin{document}
  \newlength\figureheight
  \newlength\figurewidth   
  \setlength\figureheight{0.4 \columnwidth} 
  \setlength\figurewidth{0.4 \columnwidth} 

  \begin{tikzpicture}

  \begin{axis}[%
   width=\figurewidth,
   height=\figureheight,
   view={0}{90},
   colormap/bone,
   colorbar,
   colorbar/width =0.4cm,
   colorbar style ={at={(1.1,1)},
     font = \scriptsize,
  ytick={0,0.4,0.8},
  yticklabels={$0$,$0.4$,$0.8$}
  },
   scale only axis,
   ticklabel style ={font =\scriptsize},
   xmin=-0.02, xmax=0.02,
   xtick = {-0.02,0,0.02},
   xticklabels ={-$0.02$,$0$,$0.02$},
   xlabel={$v_x$ (m/s)},
   xlabel near ticks,
   font = \scriptsize,
   ymin=-0.02, ymax=0.02,
   ytick = {-0.02,0,0.02},
   yticklabels ={-$0.02$,$0$,$0.02$},
   ylabel={$v_y$ (m/s)},
   ylabel near ticks,
   font = \scriptsize,
   zmin=-1, zmax=1,
   zticklabels={\empty},
   ]

   \addplot3[%
   surf,
   shader=faceted,
   draw=black,
   point meta=explicit,
   mesh/rows=11]
   table[meta index=3,header=false] {
   -0.02 -0.02 0 0.08
   -0.02 -0.016 0 0.0724430811050993
   -0.02 -0.012 0 0.0659696900098826
   -0.02 -0.008 0 0.0609261848469113
   -0.02 -0.004 0 0.0576888204074238
   -0.02 0 0 0.0565685424949238
   -0.02 0.004 0 0.0576888204074238
   -0.02 0.008 0 0.0609261848469113
   -0.02 0.012 0 0.0659696900098826
   -0.02 0.016 0 0.0724430811050993
   -0.02 0.02 0 0.08
   -0.016 -0.02 0 0.0724430811050993
   -0.016 -0.016 0 0.064
   -0.016 -0.012 0 0.0565685424949238
   -0.016 -0.008 0 0.0505964425626941
   -0.016 -0.004 0 0.0466476151587624
   -0.016 0 0 0.045254833995939
   -0.016 0.004 0 0.0466476151587624
   -0.016 0.008 0 0.0505964425626941
   -0.016 0.012 0 0.0565685424949238
   -0.016 0.016 0 0.064
   -0.016 0.02 0 0.0724430811050993
   -0.012 -0.02 0 0.0659696900098826
   -0.012 -0.016 0 0.0565685424949238
   -0.012 -0.012 0 0.048
   -0.012 -0.008 0 0.0407921561087423
   -0.012 -0.004 0 0.0357770876399966
   -0.012 0 0 0.0339411254969543
   -0.012 0.004 0 0.0357770876399966
   -0.012 0.008 0 0.0407921561087423
   -0.012 0.012 0 0.048
   -0.012 0.016 0 0.0565685424949238
   -0.012 0.02 0 0.0659696900098826
   -0.008 -0.02 0 0.0609261848469113
   -0.008 -0.016 0 0.0505964425626941
   -0.008 -0.012 0 0.0407921561087423
   -0.008 -0.008 0 0.032
   -0.008 -0.004 0 0.025298221281347
   -0.008 0 0 0.0226274169979695
    -0.008 0.004 0 0.025298221281347
   -0.008 0.008 0 0.032
   -0.008 0.012 0 0.0407921561087423
   -0.008 0.016 0 0.0505964425626941
   -0.008 0.02 0 0.0609261848469113
   -0.004 -0.02 0 0.0576888204074238
   -0.004 -0.016 0 0.0466476151587624
   -0.004 -0.012 0 0.0357770876399966
   -0.004 -0.008 0 0.025298221281347
   -0.004 -0.004 0 0.016
   -0.004 0 0 0.0113137084989848
   -0.004 0.004 0 0.016
   -0.004 0.008 0 0.025298221281347
   -0.004 0.012 0 0.0357770876399966
   -0.004 0.016 0 0.0466476151587624
   -0.004 0.02 0 0.0576888204074238
    0 -0.02 0 0.0565685424949238
    0 -0.016 0 0.045254833995939
    0 -0.012 0 0.0339411254969543
    0 -0.008 0 0.0226274169979695
    0 -0.004 0 0.0113137084989848
    0 0 0 0
    0 0.004 0 0.0113137084989848
    0 0.008 0 0.0226274169979695
    0 0.012 0 0.0339411254969543
    0 0.016 0 0.045254833995939
    0 0.02 0 0.0565685424949238
    0.004 -0.02 0 0.0576888204074238
    0.004 -0.016 0 0.0466476151587624
    0.004 -0.012 0 0.0357770876399966
    0.004 -0.008 0 0.025298221281347
    0.004 -0.004 0 0.016
    0.004 0 0 0.0113137084989848
    0.004 0.004 0 0.016
    0.004 0.008 0 0.025298221281347
    0.004 0.012 0 0.0357770876399966
    0.004 0.016 0 0.0466476151587624
    0.004 0.02 0 0.0576888204074238
    0.008 -0.02 0 0.0609261848469113
    0.008 -0.016 0 0.0505964425626941
    0.008 -0.012 0 0.0407921561087423
    0.008 -0.008 0 0.032
    0.008 -0.004 0 0.025298221281347
    0.008 0 0 0.0226274169979695
    0.008 0.004 0 0.025298221281347
    0.008 0.008 0 0.032
    0.008 0.012 0 0.0407921561087423
    0.008 0.016 0 0.0505964425626941
    0.008 0.02 0 0.0609261848469113
    0.012 -0.02 0 0.0659696900098826
    0.012 -0.016 0 0.0565685424949238
    0.012 -0.012 0 0.048
    0.012 -0.008 0 0.0407921561087423
    0.012 -0.004 0 0.0357770876399966
    0.012 0 0 0.0339411254969543
    0.012 0.004 0 0.0357770876399966
    0.012 0.008 0 0.0407921561087423
    0.012 0.012 0 0.048
    0.012 0.016 0 0.0565685424949238
    0.012 0.02 0 0.0659696900098826
    0.016 -0.02 0 0.0724430811050993
    0.016 -0.016 0 0.064
    0.016 -0.012 0 0.0565685424949238
    0.016 -0.008 0 0.0505964425626941
    0.016 -0.004 0 0.0466476151587624
    0.016 0 0 0.045254833995939
    0.016 0.004 0 0.0466476151587624
    0.016 0.008 0 0.0505964425626941
    0.016 0.012 0 0.0565685424949238
    0.016 0.016 0 0.064
    0.016 0.02 0 0.0724430811050993
    0.02 -0.02 0 0.08
    0.02 -0.016 0 0.0724430811050993
    0.02 -0.012 0 0.0659696900098826
    0.02 -0.008 0 0.0609261848469113
    0.02 -0.004 0 0.0576888204074238
    0.02 0 0 0.0565685424949238
    0.02 0.004 0 0.0576888204074238
    0.02 0.008 0 0.0609261848469113
    0.02 0.012 0 0.0659696900098826
    0.02 0.016 0 0.0724430811050993
    0.02 0.02 0 0.08
    };
    \end{axis}
    \end{tikzpicture}

    \end{document}
  • Is this the output from matlab2tikz, or did you manually change some things? – Jake Jun 11 '13 at 0:44
7

This happens because matlab2tikz seems to hardcode the tick labels.

Ordinarily, I would recommend to remove the xtick and xticklabels keys, but since this is the output of an external program, it's preferable to use an approach that doesn't require altering the code directly.

To remove the axis multiplier, use

\pgfplotsset{scaled ticks = false}

somewhere before the axis environment.

To get the ticks for the color bar, you need to unset the ytick option, and you need to deactivate the colorbar style key (otherwise the options given within the axis environment have higher precedence). To do this, you can put

\pgfplotsset{
    colorbar style/.code={},
    every colorbar/.append style={
        /pgf/number format/fixed
    }
} 

before the axis environment.

  • Thank you. I have one more question. How do I decrease the distance between the colorbar and the figure? – Ansu Jun 11 '13 at 2:44
  • @Ansu: You can move the colorbar closer to the plot using something like \pgfplotsset{ colorbar style/.code={}, every colorbar/.append style={ /pgf/number format/fixed, at={(1.05,1)} } }, where the 1.05 specifies that the colorbar should be placed with a gap of 5% of the axis width. – Jake Jun 11 '13 at 2:47
  • +1 for colorbar style/.code={}. I did not know you could do this! – onewhaleid Apr 22 '15 at 9:03

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.