我使用 matlab2tikz 将图形从 matlab 转换为 tikz。当我运行此代码时,我在 X 轴和 Y 轴上都得到了这个附加值 $.10^-2$。(见下图)。此外,颜色条的 ytick 也没有显示。有人能找出问题的原因并向我提出解决方案吗?
以下是代码:
\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}
答案1
发生这种情况是因为matlab2tikz
似乎对刻度标签进行了硬编码。
通常,我建议删除xtick
和xticklabels
键,但由于这是外部程序的输出,因此最好使用不需要直接更改代码的方法。
要删除轴乘数,请使用
\pgfplotsset{scaled ticks = false}
在环境之前的某个地方axis
。
要获取颜色条的刻度,您需要取消ytick
设置选项,并且需要停用该colorbar style
键(否则环境中给出的选项axis
具有更高的优先级)。为此,您可以输入
\pgfplotsset{
colorbar style/.code={},
every colorbar/.append style={
/pgf/number format/fixed
}
}
在环境之前axis
。