tikzpicture 中的子标题

tikzpicture 中的子标题

添加子标题后,我的图形从水平位置垂直对齐。最初,我的前三个图形是水平对齐的,最后一个图形位于前三个图形下方。我尝试使用子图,但仍然不起作用。

\documentclass{article}

\usepackage{tikz}
\usepackage{pgfplots}

\usepackage{caption}
\usepackage{subcaption}

\usepackage{subcaption}
\begin{document}
\begin{figure*}
%\begin{subfigure}
\begin{tikzpicture}
\begin{axis}[scatter/classes={
    %a={mark=square*,blue},%
    %b={mark=triangle*,red},%
    a={mark=triangle,draw=blue,fill=red}},width=0.3\linewidth, xlabel=Normalized execution time, ylabel=NCD]

    % \addplot[] is better than \addplot+[] here:
    % it avoids scalings of the cycle list
    \addplot[scatter,only marks,
        scatter src=explicit symbolic]
        coordinates {
            (0.2439,0.786)  [a]
            (0.2368,0.782) [a]
            (0.2488,0.792) [a]
            (0.245,0.8)  [a]
            (0.2278,0.69)   [a]
            (0.2318,0.679)   [a]
            (0.3069,0.8156) [a]
            (0.2264,0.795) [a]
            (0.3905,0.7813) [a]
            (0.4977,0.7937) [a]
            (0.1996,0.3484) [a]
            (0.20344,0.3592) [a]
            (0.186575,0.6627) [a]
            (0.1875,0.676) [a]
            (0.240,0.710)  [a]
            (0.452,0.783)   [a]
            (0.520,0.807)   [a]
            (0.255,0.615) [a]
            (0.399,0.7913) [a]


        };
\end{axis}
\end{tikzpicture}%
\subcaption{SHA}
%\end{subfigure}
\begin{subfigure}[b]{\textwidth}
\hspace{3mm}\begin{tikzpicture}
\begin{axis}[scatter/classes={
    %a={mark=square*,blue},%
    %b={mark=triangle*,red},%
    a={mark=triangle,draw=green,fill=red}}, width=0.3\linewidth,xlabel=Normalized execution time, ylabel=NCD]

    % \addplot[] is better than \addplot+[] here:
    % it avoids scalings of the cycle list
    \addplot[scatter,only marks,
        scatter src=explicit symbolic]
        coordinates {
            (0.2481,0.7963)  [a]
            (0.0979,0.7619) [a]
            (0.0600,0.586) [a]
            (0.2454,0.8025)  [a]
            (0.0366,0.2289)   [a]
            (0.2540,0.7921)   [a]
            (0.05877,0.644) [a]
            (0.2776,0.7055) [a]
            (0.2404,0.7858) [a]
            (0.0581,0.4022) [a]
            (0.2189,0.786) [a]
            (0.1426,0.616) [a]
            (0.259,0.8207) [a]
            (0.0363,0.2289) [a]
            (0.063,0.4182)  [a]
            (0.2052,0.7587)   [a]
            (0.0954,0.4884)   [a]
            (0.3049,0.7367) [a]
            (0.08015,0.6383) [a]
            (0.4344,0.747) [a]
            (0.4188,0.7418) [a]
            (0.2044,0.5975) [a]
            (0.0679,0.4271) [a]
            (0.3049,0.7367)  [a]
            (0.205,0.7587)   [a]
            (0.0679,0.427)   [a]
            (0.30494,0.7367) [a]
            (0.205,0.7587) [a]
            (0.2592,0.8207)  [a]
            (0.2052,0.758)   [a]
            (0.3049,0.736)   [a]
            (0.0801,0.63837) [a]    
            };
\end{axis}
\end{tikzpicture}%
\subcaption{blowfish}
\end{subfigure}
\begin{subfigure}[b]{\textwidth}
\begin{tikzpicture} \hspace{5mm}
\begin{axis}[scatter/classes={
    %a={mark=square*,blue},%
    %b={mark=triangle*,red},%
    a={mark=triangle,draw=red,fill=red}},width=0.3\linewidth,xlabel=Normalized execution time, ylabel=NCD]

    % \addplot[] is better than \addplot+[] here:
    % it avoids scalings of the cycle list
    \addplot[scatter,only marks,
        scatter src=explicit symbolic]
        coordinates {
            (0.290323,0.713)  [a]
            (0.267,0.6116) [a]
            (0.271,0.70) [a]
            (0.3015,0.623)  [a]
            (0.316,0.7155)   [a]
            (0.192,0.6456)   [a]
            (0.3093,0.7457) [a]
            (0.3351,0.7364) [a]
            (0.205,0.6687) [a]
            (0.2954,0.747) [a]
            (0.168,0.5053) [a]
            (0.26037,0.6145) [a]
            (0.2678,0.614) [a]
            (0.177,0.515) [a]
            (0.2695,0.617)  [a]
            (0.2670,0.6213)   [a]
            (0.230,0.637)   [a]
            (0.2611,0.607) [a]
            (0.2867,0.533) [a]
            (0.2653,0.633) [a]
            (0.257,0.5372) [a]
            (0.2718,0.5391) [a]
            (0.1893,0.4286) [a]
            (0.1881,0.43)  [a]
            (0.198,0.4313)   [a]
            (0.256,0.459)   [a]
            (0.161,0.323) [a]
            (0.160,0.323) [a]
            (0.1609,0.366)  [a]
            (0.232,0.8276)   [a]
            (0.3256,0.7945) [a]
            (0.1345,0.6789) [a]
            (0.3546,0.8356)  [a]
            (0.4345,0.814)  [a]
            (0.3986,0.8098)   [a]
            (0.423,0.643) [a]
            (0.4034,0.7567) [a]
            (0.4546,0.8134)  [a]
            };
\end{axis}
\end{tikzpicture}
\subcaption{blowfish}
\end{subfigure}

\vspace{1cm}
\begin{subfigure}[b]{\textwidth}
\begin{tikzpicture} \hspace{6cm}
\begin{axis}[scatter/classes={
    %a={mark=square*,blue},%
    %b={mark=triangle*,red},%
    a={mark=triangle,draw=gray,fill=red}},width=0.3\linewidth,width=0.3\linewidth,xlabel=Normalized execution time, ylabel=NCD]

    % \addplot[] is better than \addplot+[] here:
    % it avoids scalings of the cycle list
    \addplot[scatter,only marks,
        scatter src=explicit symbolic]
        coordinates {
            (0.1005,0.617)  [a]
            (0.1064,0.6429) [a]
            (0.112,0.6814) [a]
            (0.11065,0.6847)  [a]
            (0.1121,0.6685)   [a]
            (0.1086,0.6630)   [a]
            (0.1138,0.5973) [a]
            (0.4284,0.8154) [a]
            (0.3465,0.7735) [a]
            (0.1145,0.6801) [a]
            (0.4906,0.80218) [a]
            (0.111,0.6295) [a]
            (0.5058,0.7998) [a]
            (0.4527,0.7906) [a]
            (0.5545,0.81309)  [a]
            (0.49602,0.8021)   [a]
            (0.49227,0.7362)   [a]
            (0.5326,0.758) [a]
            (0.2365,0.7786) [a]
            (0.3168,0.8013) [a]
            (0.2127,0.7637) [a]
            (0.3096,0.8106) [a]
            (0.4263,0.7926) [a]
            (0.5216,0.7156)  [a]
            (0.2357,0.7816)   [a]
            (0.1567,0.6023) [a]
            (0.178,0.616) [a]
            (0.363,0.698) [a]
            (0.456,0.801) [a]
            (0.307,0.726) [a]
            (0.526,0.819) [a]
            (0.163,0.783)  [a]


            };
\end{axis}
\end{tikzpicture}
\subcaption{MD5}
\end{subfigure}
\caption{Plot of execution time and NCD value of benchmarks}
\label{fig:cp}

\end{figure*}
\end{document}

答案1

以下是如何设置 2x2 矩阵。请注意,子图内的\linewidth\textwidth均重置为子图宽度。

\documentclass{article}
\usepackage{showframe}% debugging tool
\usepackage{tikz}
\usepackage{pgfplots}

\usepackage{caption}
\usepackage{subcaption}

\usepackage{subcaption}
\begin{document}
\begin{figure*}
\captionsetup[subfigure]{position=above}% reduce gap between picture and caption
\begin{subfigure}[b]{0.5\textwidth}
\centering
\begin{tikzpicture}
\begin{axis}[scatter/classes={
    %a={mark=square*,blue},%
    %b={mark=triangle*,red},%
    a={mark=triangle,draw=blue,fill=red}},width=0.6\linewidth, xlabel=Normalized execution time, ylabel=NCD]

    % \addplot[] is better than \addplot+[] here:
    % it avoids scalings of the cycle list
    \addplot[scatter,only marks,
        scatter src=explicit symbolic]
        coordinates {
            (0.2439,0.786)  [a]
            (0.2368,0.782) [a]
            (0.2488,0.792) [a]
            (0.245,0.8)  [a]
            (0.2278,0.69)   [a]
            (0.2318,0.679)   [a]
            (0.3069,0.8156) [a]
            (0.2264,0.795) [a]
            (0.3905,0.7813) [a]
            (0.4977,0.7937) [a]
            (0.1996,0.3484) [a]
            (0.20344,0.3592) [a]
            (0.186575,0.6627) [a]
            (0.1875,0.676) [a]
            (0.240,0.710)  [a]
            (0.452,0.783)   [a]
            (0.520,0.807)   [a]
            (0.255,0.615) [a]
            (0.399,0.7913) [a]


        };
\end{axis}
\end{tikzpicture}
\subcaption{SHA}
\end{subfigure}% no space between subfigures
\begin{subfigure}[b]{0.5\textwidth}
\centering
\begin{tikzpicture}
\begin{axis}[scatter/classes={
    %a={mark=square*,blue},%
    %b={mark=triangle*,red},%
    a={mark=triangle,draw=green,fill=red}}, width=0.6\linewidth,xlabel=Normalized execution time, ylabel=NCD]

    % \addplot[] is better than \addplot+[] here:
    % it avoids scalings of the cycle list
    \addplot[scatter,only marks,
        scatter src=explicit symbolic]
        coordinates {
            (0.2481,0.7963)  [a]
            (0.0979,0.7619) [a]
            (0.0600,0.586) [a]
            (0.2454,0.8025)  [a]
            (0.0366,0.2289)   [a]
            (0.2540,0.7921)   [a]
            (0.05877,0.644) [a]
            (0.2776,0.7055) [a]
            (0.2404,0.7858) [a]
            (0.0581,0.4022) [a]
            (0.2189,0.786) [a]
            (0.1426,0.616) [a]
            (0.259,0.8207) [a]
            (0.0363,0.2289) [a]
            (0.063,0.4182)  [a]
            (0.2052,0.7587)   [a]
            (0.0954,0.4884)   [a]
            (0.3049,0.7367) [a]
            (0.08015,0.6383) [a]
            (0.4344,0.747) [a]
            (0.4188,0.7418) [a]
            (0.2044,0.5975) [a]
            (0.0679,0.4271) [a]
            (0.3049,0.7367)  [a]
            (0.205,0.7587)   [a]
            (0.0679,0.427)   [a]
            (0.30494,0.7367) [a]
            (0.205,0.7587) [a]
            (0.2592,0.8207)  [a]
            (0.2052,0.758)   [a]
            (0.3049,0.736)   [a]
            (0.0801,0.63837) [a]    
            };
\end{axis}
\end{tikzpicture}
\subcaption{blowfish}
\end{subfigure}\vspace{1cm}

\begin{subfigure}[b]{0.5\textwidth}
\centering
\begin{tikzpicture}
\begin{axis}[scatter/classes={
    %a={mark=square*,blue},%
    %b={mark=triangle*,red},%
    a={mark=triangle,draw=red,fill=red}},width=0.6\linewidth,xlabel=Normalized execution time, ylabel=NCD]

    % \addplot[] is better than \addplot+[] here:
    % it avoids scalings of the cycle list
    \addplot[scatter,only marks,
        scatter src=explicit symbolic]
        coordinates {
            (0.290323,0.713)  [a]
            (0.267,0.6116) [a]
            (0.271,0.70) [a]
            (0.3015,0.623)  [a]
            (0.316,0.7155)   [a]
            (0.192,0.6456)   [a]
            (0.3093,0.7457) [a]
            (0.3351,0.7364) [a]
            (0.205,0.6687) [a]
            (0.2954,0.747) [a]
            (0.168,0.5053) [a]
            (0.26037,0.6145) [a]
            (0.2678,0.614) [a]
            (0.177,0.515) [a]
            (0.2695,0.617)  [a]
            (0.2670,0.6213)   [a]
            (0.230,0.637)   [a]
            (0.2611,0.607) [a]
            (0.2867,0.533) [a]
            (0.2653,0.633) [a]
            (0.257,0.5372) [a]
            (0.2718,0.5391) [a]
            (0.1893,0.4286) [a]
            (0.1881,0.43)  [a]
            (0.198,0.4313)   [a]
            (0.256,0.459)   [a]
            (0.161,0.323) [a]
            (0.160,0.323) [a]
            (0.1609,0.366)  [a]
            (0.232,0.8276)   [a]
            (0.3256,0.7945) [a]
            (0.1345,0.6789) [a]
            (0.3546,0.8356)  [a]
            (0.4345,0.814)  [a]
            (0.3986,0.8098)   [a]
            (0.423,0.643) [a]
            (0.4034,0.7567) [a]
            (0.4546,0.8134)  [a]
            };
\end{axis}
\end{tikzpicture}
\subcaption{blowfish}
\end{subfigure}% no space
\begin{subfigure}[b]{0.5\textwidth}
\centering
\begin{tikzpicture}
\begin{axis}[scatter/classes={
    %a={mark=square*,blue},%
    %b={mark=triangle*,red},%
    a={mark=triangle,draw=gray,fill=red}},width=0.6\linewidth,xlabel=Normalized execution time, ylabel=NCD]

    % \addplot[] is better than \addplot+[] here:
    % it avoids scalings of the cycle list
    \addplot[scatter,only marks,
        scatter src=explicit symbolic]
        coordinates {
            (0.1005,0.617)  [a]
            (0.1064,0.6429) [a]
            (0.112,0.6814) [a]
            (0.11065,0.6847)  [a]
            (0.1121,0.6685)   [a]
            (0.1086,0.6630)   [a]
            (0.1138,0.5973) [a]
            (0.4284,0.8154) [a]
            (0.3465,0.7735) [a]
            (0.1145,0.6801) [a]
            (0.4906,0.80218) [a]
            (0.111,0.6295) [a]
            (0.5058,0.7998) [a]
            (0.4527,0.7906) [a]
            (0.5545,0.81309)  [a]
            (0.49602,0.8021)   [a]
            (0.49227,0.7362)   [a]
            (0.5326,0.758) [a]
            (0.2365,0.7786) [a]
            (0.3168,0.8013) [a]
            (0.2127,0.7637) [a]
            (0.3096,0.8106) [a]
            (0.4263,0.7926) [a]
            (0.5216,0.7156)  [a]
            (0.2357,0.7816)   [a]
            (0.1567,0.6023) [a]
            (0.178,0.616) [a]
            (0.363,0.698) [a]
            (0.456,0.801) [a]
            (0.307,0.726) [a]
            (0.526,0.819) [a]
            (0.163,0.783)  [a]
            };
\end{axis}
\end{tikzpicture}
\subcaption{MD5}
\end{subfigure}
\caption{Plot of execution time and NCD value of benchmarks}
\label{fig:cp}
\end{figure*}
\end{document}

演示


这显示了如何尽可能紧密地包装它们。将三个标签放在一行中的问题是由于 xlabel 和 ylabel 占用了太多空间。

\documentclass{article}
\usepackage{showframe}% debugging tool
\usepackage{tikz}
\usepackage{pgfplots}

\usepackage{caption}
\usepackage{subcaption}

\usepackage{subcaption}
\begin{document}
\begin{figure*}
\captionsetup[subfigure]{position=above}% reduce gap between picture and caption
\lineskip=1cm
\centering
\sbox0{\begin{tikzpicture}[font=\footnotesize]
\begin{axis}[scatter/classes={
    %a={mark=square*,blue},%
    %b={mark=triangle*,red},%
    a={mark=triangle,draw=blue,fill=red}},width=0.3\textwidth, xlabel=Normalized execution time, 
    ylabel=NCD, ylabel near ticks]
    % \addplot[] is better than \addplot+[] here:
    % it avoids scalings of the cycle list
    \addplot[scatter,only marks,
        scatter src=explicit symbolic]
        coordinates {
            (0.2439,0.786)  [a]
            (0.2368,0.782) [a]
            (0.2488,0.792) [a]
            (0.245,0.8)  [a]
            (0.2278,0.69)   [a]
            (0.2318,0.679)   [a]
            (0.3069,0.8156) [a]
            (0.2264,0.795) [a]
            (0.3905,0.7813) [a]
            (0.4977,0.7937) [a]
            (0.1996,0.3484) [a]
            (0.20344,0.3592) [a]
            (0.186575,0.6627) [a]
            (0.1875,0.676) [a]
            (0.240,0.710)  [a]
            (0.452,0.783)   [a]
            (0.520,0.807)   [a]
            (0.255,0.615) [a]
            (0.399,0.7913) [a]


        };
\end{axis}
\end{tikzpicture}}%
\sbox1{\begin{tikzpicture}[font=\footnotesize]
\begin{axis}[scatter/classes={
    %a={mark=square*,blue},%
    %b={mark=triangle*,red},%
    a={mark=triangle,draw=green,fill=red}}, width=0.3\textwidth,xlabel=Normalized execution time,
    ylabel=NCD, ylabel near ticks]

    % \addplot[] is better than \addplot+[] here:
    % it avoids scalings of the cycle list
    \addplot[scatter,only marks,
        scatter src=explicit symbolic]
        coordinates {
            (0.2481,0.7963)  [a]
            (0.0979,0.7619) [a]
            (0.0600,0.586) [a]
            (0.2454,0.8025)  [a]
            (0.0366,0.2289)   [a]
            (0.2540,0.7921)   [a]
            (0.05877,0.644) [a]
            (0.2776,0.7055) [a]
            (0.2404,0.7858) [a]
            (0.0581,0.4022) [a]
            (0.2189,0.786) [a]
            (0.1426,0.616) [a]
            (0.259,0.8207) [a]
            (0.0363,0.2289) [a]
            (0.063,0.4182)  [a]
            (0.2052,0.7587)   [a]
            (0.0954,0.4884)   [a]
            (0.3049,0.7367) [a]
            (0.08015,0.6383) [a]
            (0.4344,0.747) [a]
            (0.4188,0.7418) [a]
            (0.2044,0.5975) [a]
            (0.0679,0.4271) [a]
            (0.3049,0.7367)  [a]
            (0.205,0.7587)   [a]
            (0.0679,0.427)   [a]
            (0.30494,0.7367) [a]
            (0.205,0.7587) [a]
            (0.2592,0.8207)  [a]
            (0.2052,0.758)   [a]
            (0.3049,0.736)   [a]
            (0.0801,0.63837) [a]    
            };
\end{axis}
\end{tikzpicture}}%
\sbox2{\begin{tikzpicture}[font=\footnotesize]
\begin{axis}[scatter/classes={
    %a={mark=square*,blue},%
    %b={mark=triangle*,red},%
    a={mark=triangle,draw=red,fill=red}},width=0.3\textwidth,xlabel=Normalized execution time, 
    ylabel=NCD, ylabel near ticks]

    % \addplot[] is better than \addplot+[] here:
    % it avoids scalings of the cycle list
    \addplot[scatter,only marks,
        scatter src=explicit symbolic]
        coordinates {
            (0.290323,0.713)  [a]
            (0.267,0.6116) [a]
            (0.271,0.70) [a]
            (0.3015,0.623)  [a]
            (0.316,0.7155)   [a]
            (0.192,0.6456)   [a]
            (0.3093,0.7457) [a]
            (0.3351,0.7364) [a]
            (0.205,0.6687) [a]
            (0.2954,0.747) [a]
            (0.168,0.5053) [a]
            (0.26037,0.6145) [a]
            (0.2678,0.614) [a]
            (0.177,0.515) [a]
            (0.2695,0.617)  [a]
            (0.2670,0.6213)   [a]
            (0.230,0.637)   [a]
            (0.2611,0.607) [a]
            (0.2867,0.533) [a]
            (0.2653,0.633) [a]
            (0.257,0.5372) [a]
            (0.2718,0.5391) [a]
            (0.1893,0.4286) [a]
            (0.1881,0.43)  [a]
            (0.198,0.4313)   [a]
            (0.256,0.459)   [a]
            (0.161,0.323) [a]
            (0.160,0.323) [a]
            (0.1609,0.366)  [a]
            (0.232,0.8276)   [a]
            (0.3256,0.7945) [a]
            (0.1345,0.6789) [a]
            (0.3546,0.8356)  [a]
            (0.4345,0.814)  [a]
            (0.3986,0.8098)   [a]
            (0.423,0.643) [a]
            (0.4034,0.7567) [a]
            (0.4546,0.8134)  [a]
            };
\end{axis}
\end{tikzpicture}}
\sbox3{\begin{tikzpicture}[font=\footnotesize]
\begin{axis}[scatter/classes={
    %a={mark=square*,blue},%
    %b={mark=triangle*,red},%
    a={mark=triangle,draw=gray,fill=red}},width=0.3\textwidth,xlabel=Normalized execution time,
    ylabel=NCD, ylabel near ticks]
    % \addplot[] is better than \addplot+[] here:
    % it avoids scalings of the cycle list
    \addplot[scatter,only marks,
        scatter src=explicit symbolic]
        coordinates {
            (0.1005,0.617)  [a]
            (0.1064,0.6429) [a]
            (0.112,0.6814) [a]
            (0.11065,0.6847)  [a]
            (0.1121,0.6685)   [a]
            (0.1086,0.6630)   [a]
            (0.1138,0.5973) [a]
            (0.4284,0.8154) [a]
            (0.3465,0.7735) [a]
            (0.1145,0.6801) [a]
            (0.4906,0.80218) [a]
            (0.111,0.6295) [a]
            (0.5058,0.7998) [a]
            (0.4527,0.7906) [a]
            (0.5545,0.81309)  [a]
            (0.49602,0.8021)   [a]
            (0.49227,0.7362)   [a]
            (0.5326,0.758) [a]
            (0.2365,0.7786) [a]
            (0.3168,0.8013) [a]
            (0.2127,0.7637) [a]
            (0.3096,0.8106) [a]
            (0.4263,0.7926) [a]
            (0.5216,0.7156)  [a]
            (0.2357,0.7816)   [a]
            (0.1567,0.6023) [a]
            (0.178,0.616) [a]
            (0.363,0.698) [a]
            (0.456,0.801) [a]
            (0.307,0.726) [a]
            (0.526,0.819) [a]
            (0.163,0.783)  [a]
            };
\end{axis}
\end{tikzpicture}}%
\begin{subfigure}[b]{\wd0}
\usebox0
\subcaption{SHA}
\end{subfigure}\hfill
\begin{subfigure}[b]{\wd1}
\usebox1
\subcaption{blowfish}
\end{subfigure}\hfill
\begin{subfigure}[b]{\wd2}
\usebox2
\subcaption{blowfish}
\end{subfigure}\hfill
\begin{subfigure}[b]{\wd3}
\usebox3
\subcaption{MD5}
\end{subfigure}
\caption{Plot of execution time and NCD value of benchmarks}
\label{fig:cp}
\end{figure*}
\end{document}

演示2

相关内容