tikzpicture 并排不适用于 pgfplots

tikzpicture 并排不适用于 pgfplots

我需要将图表并排对齐。我尝试使用 \qquad 和 \hspace,但两者都不起作用。以下是代码。

\documentclass{article}

\usepackage{tikz}
\usepackage{pgfplots}

\usepackage{subcaption}


\begin{document}
\begin{figure}[h]  
\centering 

\begin{tikzpicture}
\begin{axis}[legend pos=south east, ylabel = NCD, ymin=0,ymax=1, xlabel = Relative execution time, xmin=1, xmax=10, xtick={1,2,3,4,5,6,7,8,9,10},]
    \addplot[
        scatter,only marks,scatter src=explicit symbolic,
        scatter/classes={
            ModExp={mark=square*,black},
            MulMod16={mark=square*,red},
           % AES={mark=o,draw=black,fill=white}
             AES={mark=square*,green},
             SHA={mark=square*,yellow},
             blowfish={mark=square*,brown},
             MD5={mark=square*,cyan}
        }
    ]
    table[x=x,y=y,meta=label]{
        x    y    label
        1.393  0.6248 ModExp
        3.348 0.7095 MulMod16
        1.503 0.663451 AES
        2.57 0.63203  SHA
        1.581  0.6059  blowfish
        9.3  0.7613  MD5
           };
    \legend{ModExp,MulMod16,AES,SHA,blowfish,MD5 }
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[legend pos=south east, ylabel = NCD, ymin=0,ymax=1, xlabel = Relative execution time, xmin=1, xmax=10, xtick={1,2,3,4,5,6,7,8,9,10},]
    \addplot[
        scatter,only marks,scatter src=explicit symbolic,
        scatter/classes={
            ModExp={mark=square*,black},
            MulMod16={mark=square*,red},
           % AES={mark=o,draw=black,fill=white}
             AES={mark=square*,green},
             SHA={mark=square*,yellow},
             blowfish={mark=square*,brown},
             MD5={mark=square*,cyan}
        }
    ]
    table[x=x,y=y,meta=label]{
        x    y    label
        1.393  0.6248 ModExp
        3.348 0.7095 MulMod16
        1.503 0.663451 AES
        2.57 0.63203  SHA
        1.581  0.6059  blowfish
        9.3  0.7613  MD5
           };
    \legend{ModExp,MulMod16,AES,SHA,blowfish,MD5 }
\end{axis}
%%\caption{Plot of execution time and NCD value for a random/unintelligible application of obfuscation transformation function -sub, -bcf, -split\_num=7}
%\label{fig:cp}
\end{tikzpicture}

\end{figure}

\end{document}

答案1

  • 你的图表太宽,无法放在一行中。将其宽度减少到0.5\linewidth
  • 标题应该在tikzpicture环境之外

编辑:

根据下面的评论,我更改了代码如下: - 将常用选项移至\pgfplotsset此图 - 添加是legend style - 定义是图表高度考虑到上述情况代码要短得多并且图例不再覆盖图表中的标记。现在更好了吗?

在此处输入图片描述

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{subcaption}

\begin{document}
    \begin{figure}[h¸tb]
    \pgfplotsset{width=0.5\linewidth,
                 height=0.5\linewidth,
                 ylabel = NCD,
                 ymin=0,ymax=1,
                 xlabel = Relative execution time,
                 xmin=1, xmax=10,
                 xtick={1,2,...,10},
                 scatter,
                 scatter src=explicit symbolic,
                 scatter/classes={
                    ModExp={mark=square*,black},
                    MulMod16={mark=square*,red},
                    AES={mark=square*,green},
                    SHA={mark=square*,yellow},
                    blowfish={mark=square*,brown},
                    MD5={mark=square*,cyan}
                         },
                 legend style={
                 font=\small,
                 cells={anchor=west},
                 legend pos=outer north east,
                 legend pos=south east},
                }% end of pgfplotsset
\centering
\begin{tikzpicture}
\begin{axis}
    \addplot[only marks]
    table[x=x,y=y,meta=label]{
        x    y    label
        1.393  0.6248   ModExp
        3.348  0.7095   MulMod16
        1.503  0.663451 AES
        2.57   0.63203  SHA
        1.581  0.6059   blowfish
        9.3  0.7613     MD5
           };
    \legend{ModExp,MulMod16,AES,SHA,blowfish,MD5}
\end{axis}
\end{tikzpicture}
\hfill
\begin{tikzpicture}
\begin{axis}
    \addplot[only marks]
    table[x=x,y=y,meta=label]{
        x    y    label
        1.393  0.6248   ModExp
        3.348  0.7095   MulMod16
        1.503  0.663451 AES
        2.57   0.63203  SHA
        1.581  0.6059   blowfish
        9.3  0.7613     MD5
           };
    \legend{ModExp,MulMod16,AES,SHA,blowfish,MD5}
\end{axis}
\end{tikzpicture}
\caption{Plot of execution time and NCD value for a random/unintelligible application of obfuscation transformation function -sub, -bcf, -split\_num=7}
\label{fig:cp}
    \end{figure}
\end{document}

相关内容