Latex 中条形图的定位

Latex 中条形图的定位

我尝试在 subfigure 中使用 tikzpicture 并排绘制两个条形图。在我的文档中,它看起来像这样:

在此处输入图片描述

这看起来不太好。问题是:

  1. 它涵盖了部分文本。
  2. 两个条形图彼此距离太近。

下一步该如何进行?

我使用了以下内容:

\begin{figure}[h]
%\begin{center}
\begin{tikzpicture}
  \begin{subfigure}[b]{0.45\textwidth}
    \begin{axis}[
        height=75mm,
        x tick label style={/pgf/number format/1000 sep=},
        ylabel=YLABEL,
        xlabel= {XLABEL},
        legend style={
          at={(0,1)},
          anchor=north west,
        },
        nodes near coords,
        every node near coord/.append style={font=\tiny},
        ybar=0pt,
        bar width=6pt
      ]
      \addplot[gray!20!gray,fill=gray!80!gray]
        coordinates {(01,0.150) (02,0.166)
          (03,0.174) (04,0.186) (05,0.187) (06,0.152) (07,0.218) (08,0.187) (09,0.156)};
      \addplot[black!20!black,fill=black!80!black]
        coordinates {(01,0.153) (02,0.162) 
          (03,0.178) (04,0.177) (05,0.222) (06,0.233) (07,0.323) (08,0.301) (09,0.233)};
      \legend{Measured, Model}
    \end{axis}
    \caption[BLABLA]
{{\small BLABLA123}}    
    \end{subfigure}
    \hfill
\begin{subfigure}[b]{0.45\textwidth}
 \begin{axis}[
      height=75mm,% 
        x tick label style={/pgf/number format/1000 sep=},
        ylabel=YLABEL,
        xlabel= {XLABEL},
        legend style={
          at={(0,1)},
          anchor=north west,
        },
        nodes near coords,
        every node near coord/.append style={font=\tiny},
        ybar=0pt,
        bar width=6pt
      ]
      \addplot[gray!20!gray,fill=gray!80!gray]
        coordinates {(01,0.150) (02,0.166)
          (03,0.174) (04,0.186) (05,0.187) (06,0.152) (07,0.218) (08,0.187) (09,0.156)};
      \addplot[black!20!black,fill=black!80!black]
        coordinates {(01,0.153) (02,0.162) 
          (03,0.178) (04,0.177) (05,0.222) (06,0.233) (07,0.323) (08,0.301) (09,0.233)};
      \legend{Measured, Model}
    \end{axis}
        \caption[BLABLA456]
{{\small BLABLA567}}    
    \end{subfigure}
\end{tikzpicture}
%\end{center}
\end{figure}

答案1

你没有:

  • subfigure环境中嵌套环境tikzpicture
  • caption里面tikzpicture
  • 在 caption 中定义标题的字体大小。它和其他选项应该在 preamble 中定义captionsetup

重组您的 MWE 后,我获得:

在此处输入图片描述

在 MWE 中,我还添加了showframeoage 布局是 wisibel 的包,在文档制作中必须将其删除。完整代码如下:

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.13}
\usepackage{subcaption}

\usepackage[a4paper,
            margin=25mm,
            showframe
            ]{geometry}

\begin{document}
    \begin{figure}[htb]
\centering
    \begin{subfigure}[b]{0.45\textwidth}
\begin{tikzpicture}
    \begin{axis}[
        height=75mm,
        x tick label style={/pgf/number format/1000 sep=},
        ylabel=YLABEL,
        xlabel= {XLABEL},
        legend style={
          at={(0,1)},
          anchor=north west,
        },
        nodes near coords,
        every node near coord/.append style={font=\tiny},
        ybar=0pt,
        bar width=6pt
      ]
      \addplot[gray!20!gray,fill=gray!80!gray]
        coordinates {(01,0.150) (02,0.166)
          (03,0.174) (04,0.186) (05,0.187) (06,0.152) (07,0.218) (08,0.187) (09,0.156)};
      \addplot[black!20!black,fill=black!80!black]
        coordinates {(01,0.153) (02,0.162)
          (03,0.178) (04,0.177) (05,0.222) (06,0.233) (07,0.323) (08,0.301) (09,0.233)};
      \legend{Measured, Model}
    \end{axis}
\end{tikzpicture}
    \caption[BLABLA]{BLABLA123}
\end{subfigure}
    \hfil
\begin{subfigure}[b]{0.45\textwidth}
    \begin{tikzpicture}
\begin{axis}[
      height=75mm,%
        x tick label style={/pgf/number format/1000 sep=},
        ylabel=YLABEL,
        xlabel= {XLABEL},
        legend style={
          at={(0,1)},
          anchor=north west,
        },
        nodes near coords,
        every node near coord/.append style={font=\tiny},
        ybar=0pt,
        bar width=6pt
      ]
      \addplot[gray!20!gray,fill=gray!80!gray]
        coordinates {(01,0.150) (02,0.166)
          (03,0.174) (04,0.186) (05,0.187) (06,0.152) (07,0.218) (08,0.187) (09,0.156)};
      \addplot[black!20!black,fill=black!80!black]
        coordinates {(01,0.153) (02,0.162)
          (03,0.178) (04,0.177) (05,0.222) (06,0.233) (07,0.323) (08,0.301) (09,0.233)};
      \legend{Measured, Model}
    \end{axis}
\end{tikzpicture}
        \caption[BLABLA456]{BLABLA567}
    \end{subfigure}
    \end{figure}
\end{document}

相关内容