让图例更接近

让图例更接近

我希望将左侧图表的图例移近图形,而对于右侧图表,我希望让 x 轴和 y 轴像左侧图表一样出现(这样 x 轴的 1 左侧和 9 右侧会有一些额外的空格,类似于 y 轴),以下是图表和代码

在此处输入图片描述

\documentclass[9pt]{sig-alternate}
% GRAPHICS
\usepackage{pgf}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{arrows,automata,positioning}
\begin{document}
\pgfplotsset{
xticklabel={$\mathsf{\pgfmathprintnumber{\tick}}$},
every axis/.append style={
font=\sffamily,
  width=6.5cm,
    height=4.9cm
}
}
\begin{figure*}[t]
\begin{minipage}{0.5\linewidth}
\centering
\scriptsize
 \begin{tikzpicture}[font=\sffamily]
\begin{semilogyaxis}[title=Dataset 1,
                legend pos=outer north east,
                legend style={draw=none},
                xtick={1,2,...,9}, % new bit
                scaled ticks=false,
                log ticks with fixed point={1000 sep=},
                axis x line=bottom,
                axis y line=left,
                axis line style=-,
                minor tick style={draw=none},
                enlargelimits,
                ylabel = Solving Time (ms),
                xlabel = Service Class Size
                ]
\addplot plot coordinates{(1,5302)(2,5585)(3,5890)(4,5645)(5,5813)(6,7117)(7,8388)(8,8350)(9,8831)};
\addplot plot coordinates{(1,2)(2,2)(3,2)(4,2)(5,2)(6,3617)(7,2755)(8,2644)(9,3466)};
\addplot plot coordinates{(1,2)(2,3)(3,4)(4,2)(5,3)(6,2341)(7,3320)(8,2298)(9,3183)};
\addplot plot coordinates{(1,1)(2,2)(3,3)(4,2)(5,2)(6,4)(7,4)(8,5)(9,32)};
\addplot plot coordinates{(1,2)(2,2)(3,3)(4,2)(5,2)(6,5)(7,4)(8,4)(9,33)};
\legend{$a$,$b$,$c$,$d$,$e$}
\end{semilogyaxis}
\end{tikzpicture}
\end{minipage}% new bit
\begin{minipage}{0.5\linewidth}
\centering
\scriptsize
 \begin{tikzpicture}[font=\sffamily]
\begin{axis}[title=\textbf{Dataset 2},
    legend pos=outer north east,
                ymin=99.4,
                legend pos=outer north east,
                legend style={draw=none},
                xtick={1,2,...,9},
                scaled ticks=false,
                log ticks with fixed point={1000 sep=},
                axis x line=bottom,
                axis y line=left,
                axis line style=-,
                minor tick style={draw=none},
        ylabel = Optimality (\%),
        xlabel = Number of Constraints
]
\addplot plot coordinates{(1,100)(2,100)(3,100)(4,100)(5,100)(6,99.82)(7,99.84)(8,99.59)(9,99.65)};
\addplot plot coordinates{(1,100)(2,100)(3,100)(4,100)(5,100)(6,99.44)(7,100)(8,99.78)(9,99.73)};
\addplot plot coordinates{(1,100)(2,100)(3,100)(4,100)(5,100)(6,99.82)(7,99.74)(8,99.74)(9,99.86)};
\addplot plot coordinates{(1,100)(2,100)(3,100)(4,100)(5,100)(6,99.82)(7,99.74)(8,99.74)(9,99.86)};
\legend{$a$,$b$,$c$,$d$}
\end{axis}
\end{tikzpicture}
\end{minipage}%
\end{figure*}
 \end{document} 

答案1

要移动图例,您可以使用every axis legend/.append style=引入适当的偏移;对于右侧图中的标签问题,您可以设置enlargelimits=true

\documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage{pgf}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{arrows,automata,positioning}
\begin{document}
\pgfplotsset{
xticklabel={$\mathsf{\pgfmathprintnumber{\tick}}$},
every axis/.append style={
font=\sffamily,
  width=6.5cm,
    height=4.9cm
}
}
\begin{figure*}[t]
\begin{minipage}{0.5\linewidth}
\centering
\scriptsize
 \begin{tikzpicture}[font=\sffamily]
\begin{semilogyaxis}[title=Dataset 1,
                legend pos=outer north east,
                legend style={draw=none},
                xtick={1,2,...,9}, % new bit
                scaled ticks=false,
                log ticks with fixed point={1000 sep=},
                axis x line=bottom,
                axis y line=left,
                axis line style=-,
                minor tick style={draw=none},
                enlargelimits,
                ylabel = Solving Time (ms),
                xlabel = Service Class Size,
               every axis legend/.append style={xshift=-10pt}
                ]
\addplot plot coordinates{(1,5302)(2,5585)(3,5890)(4,5645)(5,5813)(6,7117)(7,8388)(8,8350)(9,8831)};
\addplot plot coordinates{(1,2)(2,2)(3,2)(4,2)(5,2)(6,3617)(7,2755)(8,2644)(9,3466)};
\addplot plot coordinates{(1,2)(2,3)(3,4)(4,2)(5,3)(6,2341)(7,3320)(8,2298)(9,3183)};
\addplot plot coordinates{(1,1)(2,2)(3,3)(4,2)(5,2)(6,4)(7,4)(8,5)(9,32)};
\addplot plot coordinates{(1,2)(2,2)(3,3)(4,2)(5,2)(6,5)(7,4)(8,4)(9,33)};
\legend{$a$,$b$,$c$,$d$,$e$}
\end{semilogyaxis}
\end{tikzpicture}
\end{minipage}% new bit
\begin{minipage}{0.5\linewidth}
\centering
\scriptsize
 \begin{tikzpicture}[font=\sffamily]
\begin{axis}[title=\textbf{Dataset 2},
    legend pos=outer north east,
                ymin=99.4,
                legend pos=outer north east,
                legend style={draw=none},
                xtick={1,2,...,9},
                scaled ticks=false,
                log ticks with fixed point={1000 sep=},
                axis x line=bottom,
                axis y line=left,
                axis line style=-,
                minor tick style={draw=none},
        ylabel = Optimality (\%),
        xlabel = Number of Constraints,
               enlargelimits=true
]
\addplot plot coordinates{(1,100)(2,100)(3,100)(4,100)(5,100)(6,99.82)(7,99.84)(8,99.59)(9,99.65)};
\addplot plot coordinates{(1,100)(2,100)(3,100)(4,100)(5,100)(6,99.44)(7,100)(8,99.78)(9,99.73)};
\addplot plot coordinates{(1,100)(2,100)(3,100)(4,100)(5,100)(6,99.82)(7,99.74)(8,99.74)(9,99.86)};
\addplot plot coordinates{(1,100)(2,100)(3,100)(4,100)(5,100)(6,99.82)(7,99.74)(8,99.74)(9,99.86)};
\legend{$a$,$b$,$c$,$d$}
\end{axis}
\end{tikzpicture}
\end{minipage}%
\end{figure*}
 \end{document} 

在此处输入图片描述

我用了

\documentclass{article}
\usepackage[margin=2cm]{geometry}

在我的例子中,因为我没有你的文档类。

相关内容