如何用指数精确控制两个独立图的高度

如何用指数精确控制两个独立图的高度

我使用 pgfplots 包绘制了两个独立图。我想要这两个图具有相同的高度,但是我失败了。

这是我的论文中显示的图像。 论文中显示的图像 如你所见,右边的比左边的稍微高一点。

我尝试过这些事情:

  1. 使用scaled x ticks=false。此方法可以解决此问题。但是,数字太接近,这是我所不希望的。我怀疑这是由指数引起的。所以我接下来尝试了 2。

  2. 将指数移动到其他位置

    every x tick scale label/.style={ at={(rel axis cs:0.9,-0.2)} }

    但这个问题还没能解决,它们还是没有达到同样的高度。

左图的代码:

\usepackage{pgfplots, pgfplotstable}
\pgfplotsset{compat=1.16}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{mathpazo}

\begin{document}
\pgfplotstableread[col sep=&, header=true]{
noise level   &rmse    &mean error
0             &13.8735 &5.4890
0.001         &14.8757 &5.6138
0.002         &16.6551 &5.8121
0.003         &18.1159 &6.0338
0.004         &20.0011 &6.2824
0.005         &21.9840 &6.5650
0.006         &23.8113 &6.8693
0.007         &25.8505 &7.1813
0.008         &27.4285 &7.5026
0.009         &29.4434 &7.8572
0.01          &31.1316 &8.2160
}\datatableentry



\begin{tikzpicture}
\begin{axis}[
  major grid style={line width=.5pt,draw=gray!50},
  title={\quad},
  xtick ={0.000,0.002,...,0.010},
  minor xtick ={0.001,0.003,...,0.01},
  ymajorgrids,
%  yminorgrids,
  xtick pos=left,
  ytick pos=left,
  scaled x ticks=true,
  ymin=0,
  xmin=0,
  xmax=0.01,
  ymax=40,
  legend style={legend pos= north west, legend cell align=left},
  mark size=2,
  xlabel={$p$},
  ylabel={Value (m)},
  tick scale binop=\times,
  semithick,
  height=5cm,
  mark repeat={2},
  every  x tick scale label/.style={
    at={(rel axis cs:0.9,-0.2)},overlay
  },
]
% red,gray,yellow,green,lime,black,red,blude,cyan
\addlegendentry{RMSE};
\addplot [color=orange,thick,mark=o] table [y=rmse, x=noise level] {\datatableentry};
\addlegendentry{mean error};
\addplot [color=cyan,thick,mark=diamond] table [y=mean error, x=noise level] {\datatableentry};
\end{axis}
\end{tikzpicture}
\end{document}

正确情节的代码

\documentclass{standalone}
\usepackage{pgfplots, pgfplotstable}
\pgfplotsset{compat=1.16}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{mathpazo}

\begin{document}
\pgfplotstableread[col sep=&, header=true]{
noise level   &rmse    &mean error
0             &13.8735 &5.4890
0.2           &13.8491 &5.4878
0.4           &14.1604 &5.5624
0.6           &14.2584 &5.6174
0.8           &14.5146 &5.7072
1.0           &15.0029 &5.8409
1.2           &14.9655 &5.9318
1.4           &15.2164 &6.0813
1.6           &15.5703 &6.2642
1.8           &15.9604 &6.4683
2.0           &16.4144 &6.7071
2.2           &16.8802 &6.9842
2.4           &17.6332 &7.3055
2.6           &18.2558 &7.6403
2.8           &19.1625 &8.0250
3.0           &19.9934 &8.4352
}\datatableentry



\begin{tikzpicture}
\begin{axis}[
  %grid style={line width=.1pt, draw=gray!20},
  major grid style={line width=.5pt,draw=gray!50},
  title={\quad},
%  minor y tick num=4,
%   xtick=data,
  xtick ={0,1,...,3},
  minor xtick={0.2,0.4,...,3},
  ymajorgrids,
%  yminorgrids,
  xtick pos=left,
  ytick pos=left,
  scaled y ticks=true,
  ymin=0,
  xmin=0,
  xmax=3,
  ymax=25,
  ytick={0,5,...,25},
  legend style={legend pos= north west,legend cell align=left},
  mark size=2,
  xlabel={$\sigma_n$(degrees)},
  ylabel={Value (m)},
  tick scale binop=\times,
  height=5cm,
  semithick,
  mark repeat={2},
  scaled x ticks={base 10:0}
]
% red,gray,yellow,green,lime,black,red,blude,cyan
\addlegendentry{RMSE};
\addplot [color=orange,thick,mark=o] table [y=rmse, x=noise level] {\datatableentry};
\addlegendentry{mean error};
\addplot [color=cyan,thick,mark=diamond] table [y=mean error, x=noise level] {\datatableentry};
\end{axis}
\end{tikzpicture}
\end{document}

它们像这样插入到论文中:

\begin{figure}[htb]
  \centering
  \subfloat[Performance  under different levels of increment noise]{\includegraphics[height=4cm]{incremental_noise/incremental_noise}}
\hspace{.5cm}
  \subfloat[Performance  under different levels of deviation noise]{\includegraphics[height=4cm]{deviation_noise/deviation_noise}}
  \caption{Resistence to different kind of noise.}
  \label{fig:noise_resistence}
\end{figure}

您有解决这个问题的办法吗?谢谢!

答案1

我知道该怎么做才能解决这个问题。我添加了\raisebox{-0.25ex}[0pt][0pt]我的主要 tex 文件,结果看起来不错。请参阅此答案更多细节。

相关内容