删除 pgfplot 右侧的白色 space

Remove white space on right side of pgfplot

目前我有以下数字(图):

我已将 pgfplots 放在两个子图中,以便我可以添加标题。然而,问题是在图 3b 的右侧添加了一些白色 space。我正在使用 \hfill 选项,但这个白色 space 仍然被删除。有人知道如何去掉这个白色 space 使得图 3b 的右手边与我论文的边框对齐(由 text text text 表示...)

我的代码如下:

\documentclass[a4paper, 11pt]{article}
\usepackage[utf8x]{inputenc}
\usepackage[margin=2.5cm]{geometry}
\usepackage{subcaption}
\usepackage{float}
\usepackage{graphicx}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{positioning}
\tikzset{font=\footnotesize}

\begin{document}

\begin{figure}[H]
\centering

\begin{subfigure}{0.49\textwidth}

\begin{tikzpicture}
    \begin{axis}[
        title={},
        xlabel={Epochs},
        ylabel={Rewards},
        ylabel near ticks,
        legend pos=south east,
        ymajorgrids=true,
        grid style=densely dotted,
        width=7cm,
        height=6cm,
        legend cell align={left},
        legend style={font=\footnotesize}
    ]
    \addplot[color = black, line width = 0.25mm, mark = *, mark size = 1] coordinates {
        (1, 1.5)(2, 1.3)
        };
    \addplot[color = black, line width = 0.25mm, mark = none, samples = 2, dashed] {1.4}; % Constant line
    \legend{Plot1,}
    \end{axis}
    \begin{axis}[
        ylabel={Percentage (\%)},
        axis y line*=right,
        ylabel near ticks,
        ylabel style={rotate=-180},
        hide x axis,
        width=7cm,
        height=6cm,
        legend style={font=\footnotesize}
    ]
    \addplot[color = black, mark = *, mark size = 1] coordinates {
    (1, 0.5)(2, 0.6)
    }; 
    \addplot[color = black, line width = 0.25mm, mark = none, samples = 2, dashed] {0.53}; % Constant line
    \legend{Plot2,}
    \end{axis}
\end{tikzpicture}

\caption{Performance}
\label{Plot:}
\end{subfigure}\hfill
\begin{subfigure}{0.49\textwidth}

\begin{tikzpicture}
    \begin{axis}[
        title={},
        xlabel={Epochs},
        ylabel={Rewards},
        ylabel near ticks,
        legend pos=south east,
        ymajorgrids=true,
        grid style=densely dotted,
        width=7cm,
        height=6cm,
        legend cell align={left},
        legend style={font=\footnotesize}
    ]
    \addplot[color = black, line width = 0.25mm, mark = *, mark size = 1] coordinates {
        (1, 1.5)(2, 1.3)
        };
    \addplot[color = black, line width = 0.25mm, mark = none, samples = 2, dashed] {1.4}; % Constant line
    \legend{Plot1,}
    \end{axis}
\end{tikzpicture}

\caption{Action distribution}
\label{Plot:}
\end{subfigure}

\caption{Results}
\label{Plot:}
\end{figure}

\end{document}

问题是您的地块大约有 7 厘米宽,并且您将它们放置在 subfigure.49\textwidth 中,因此 \hfill 您放置在 subfigure 之间s只看到.49\textwidth的objects,按此添加填充space。如果你想把情节向右边界移动,你可以

a) 将 \hfill 放入子图中(标题不再居中)

b) 调整 .49\textwidth 以匹配绘图的实际宽度(大约 7 厘米)

(下面代码中的\fbox{...}只是为了可视化地块的大小)

\documentclass[a4paper, 11pt]{article}
\usepackage[utf8x]{inputenc}
\usepackage[margin=2.5cm,showframe]{geometry}
\usepackage{subcaption}
\usepackage{float}
\usepackage{graphicx}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{positioning}
\tikzset{font=\footnotesize}

\begin{document}

\begin{figure}[H]
\centering

\begin{subfigure}{0.49\textwidth}

\fbox{\begin{tikzpicture}
    \begin{axis}[
        title={},
        xlabel={Epochs},
        ylabel={Rewards},
        ylabel near ticks,
        legend pos=south east,
        ymajorgrids=true,
        grid style=densely dotted,
        width=7cm,
        height=6cm,
        legend cell align={left},
        legend style={font=\footnotesize}
    ]
    \addplot[color = black, line width = 0.25mm, mark = *, mark size = 1] coordinates {
        (1, 1.5)(2, 1.3)
        };
    \addplot[color = black, line width = 0.25mm, mark = none, samples = 2, dashed] {1.4}; % Constant line
    \legend{Plot1,}
    \end{axis}
    \begin{axis}[
        ylabel={Percentage (\%)},
        axis y line*=right,
        ylabel near ticks,
        ylabel style={rotate=-180},
        hide x axis,
        width=7cm,
        height=6cm,
        legend style={font=\footnotesize}
    ]
    \addplot[color = black, mark = *, mark size = 1] coordinates {
    (1, 0.5)(2, 0.6)
    }; 
    \addplot[color = black, line width = 0.25mm, mark = none, samples = 2, dashed] {0.53}; % Constant line
    \legend{Plot2,}
    \end{axis}
\end{tikzpicture}}

\caption{Performance}
\label{Plot:}
\end{subfigure}
\begin{subfigure}{0.49\textwidth}
\hfill%
\fbox{\begin{tikzpicture}
    \begin{axis}[
        title={},
        xlabel={Epochs},
        ylabel={Rewards},
        ylabel near ticks,
        legend pos=south east,
        ymajorgrids=true,
        grid style=densely dotted,
        width=7cm,
        height=6cm,
        legend cell align={left},
        legend style={font=\footnotesize}
    ]
    \addplot[color = black, line width = 0.25mm, mark = *, mark size = 1] coordinates {
        (1, 1.5)(2, 1.3)
        };
    \addplot[color = black, line width = 0.25mm, mark = none, samples = 2, dashed] {1.4}; % Constant line
    \legend{Plot1,}
    \end{axis}
\end{tikzpicture}}%
\caption{Action distribution}
\label{Plot:}
\end{subfigure}
\caption{Results}
\label{Plot:}
\end{figure}

\end{document}