连续两个条形图超出页面范围

连续两个条形图超出页面范围

我正在尝试制作两个并排的条形图,但当我编译它时,第二个条形超出了页面范围,并且条形的标题不在蝙蝠图的中心。这是我的代码:

\documentclass{article}    

\usepackage{pgfplots}
\usepackage{bchart}
\usepackage{caption}

\definecolor{RYB1}{RGB}{218,232,252}
\definecolor{RYB2}{RGB}{245,245,245}    

\begin{document}

        \begin{figure}[H]
        \centering
        \captionsetup{justification=centering}
             \begin{minipage}{0.28\textwidth}
             \centering
                \begin{tikzpicture}
                    \begin{axis}[
                    symbolic x coords={t1, t2, t3},
                    xtick=data,
                    ylabel=PC(\%),
                    xticklabel style={rotate=45,anchor=north east},
                    ymajorgrids,
                    bar width=17pt,
                    ]
                    \addplot[ybar,fill=RYB1] coordinates {
                        (t1, 44.71) 
                        (t2, 26.57) 
                        (t3, 45.42) 
                    };
                    \end{axis}
                \end{tikzpicture}
             \caption {caption1}
             \label{Fig:lagel112}
            \end{minipage}\hfill
           \begin {minipage}{0.28\textwidth}
            \centering
                \begin{tikzpicture}
                \begin{axis}[
                symbolic x coords={t1, t2, t3},
                xtick=data,
                ylabel=AA(\%),
                xticklabel style={rotate=45,anchor=north east},
                ymajorgrids,
                bar width=17pt,
                ]
                \addplot[ybar,fill=RYB1] coordinates {
                    (t1, 66.57) 
                    (t2, 75.30) 
                    (t3, 82.84) 
                };
                 \end{axis}
            \end{tikzpicture}
            \caption {caption2}
        \label{Fig:lagel112}
        \end{minipage}
        \end{figure}

    \end{document}

答案1

在此处输入图片描述

您应该将图表宽度与minipage宽度相等:

 \documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{bchart}
\usepackage{caption}

\definecolor{RYB1}{RGB}{218,232,252}
\definecolor{RYB2}{RGB}{245,245,245}


\begin{document}
    \begin{figure}[htb]
\pgfplotsset{BAR/.style={% common style fort both pgfplots diagrams
    width=\linewidth,    % limit diagrams width to width of minipages
    symbolic x coords={t1, t2, t3},
    xtick=data,
    xticklabel style={rotate=45,anchor=north east},
    ymajorgrids,
    bar width=12pt,
    ybar,
    enlargelimits=0.15}
            }
    \centering
\captionsetup{justification=centering}
 \begin{minipage}{0.48\textwidth}
    \centering
    \begin{tikzpicture}
    \begin{axis}[BAR,
        ylabel=PC(\%) % <--- y axis labels are different
                ]
    \addplot[fill=RYB1] coordinates {
        (t1, 44.71)
        (t2, 26.57)
        (t3, 45.42)
    };
    \end{axis}
    \end{tikzpicture}
 \caption {caption1}
    \label{Fig:lagel112}
\end{minipage}\hfill
\begin{minipage}{0.48\textwidth}
    \centering
    \begin{tikzpicture}
    \begin{axis}[BAR,
        ylabel=AA(\%) % <--- y axis labels are different
                ]
    \addplot[fill=RYB1] coordinates {
        (t1, 66.57)
        (t2, 75.30)
        (t3, 82.84)
    };
     \end{axis}
    \end{tikzpicture}
\caption {caption2}
    \label{Fig:lagel112}
\end{minipage}
    \end{figure}
\end{document}

相关内容