tikzpictures 并排缩小

tikzpictures 并排缩小

如何使用 subfigure 在一个图中获取两个 tikzpicture,并将它们缩小一点以适合页面?如果无论如何都适合,则不需要进行缩小。

\documentclass[11pt,a4paper,bibtotoc,idxtotoc,headsepline,footsepline,footexclude,BCOR12mm,DIV13]{scrbook}

\usepackage{pgfplots} 

\begin{document}

\begin{figure}
\centering
\begin{subfigure}[h]{}
\begin{tikzpicture}
    \begin{loglogaxis}[legend pos=north west]
        \addplot coordinates {(1000000,0.000043)(10000000,0.000208)(100000000,0.001435)(1000000000,0.024813)(10000000000,0.052237)(100000000000,0.392075)(1000000000000,7.640320)};
        \addlegendentry{Eigen Sparse};
        \addplot coordinates {(1000000,0.000038)(10000000,0.000102)(100000000,0.000687)(1000000000,0.004481)(10000000000,0.039102)(100000000000,0.473834)(1000000000000,4.163624)};
        \addlegendentry{Eigen Dense};
        \addplot coordinates {(1000000,0.000250)(10000000,0.002253)(100000000,0.023046)(1000000000,0.226521)(10000000000,2.256439)(100000000000,22.539281)(1000000000000,228.897577)};
        \addlegendentry{Taco Sparse};
        \addplot coordinates {(1000000,0.000164)(10000000,0.001970)(100000000,0.019437)(1000000000,0.193552)(10000000000,2.324910)(100000000000,22.873258)(1000000000000,228.062183)};
        \addlegendentry{Taco Dense};
    \end{loglogaxis}
\end{tikzpicture}
\end{subfigure}
\begin{subfigure}[h]{}
\begin{tikzpicture}
    \begin{loglogaxis}[legend pos = north west]
        \addplot coordinates {(1000000,0.000006)(10000000,0.000021)(100000000,0.000191)(1000000000,0.001376)(10000000000,0.014545)(100000000000,0.152963)(1000000000000,3.680731)};
        \addlegendentry{Eigen Sparse};
        \addplot coordinates {(1000000,0.000037)(10000000,0.000126)(100000000,0.001479)(1000000000,0.012454)(10000000000,0.085147)(100000000000,1.099040)(1000000000000,9.001991)};
        \addlegendentry{Eigen Dense};
        \addplot coordinates {(1000000,0.000066)(10000000,0.000474)(100000000,0.004661)(1000000000,0.047827)(10000000000,0.448608)(100000000000,4.491783)(1000000000000,47.770237)};
        \addlegendentry{Taco Sparse};
        \addplot coordinates {(1000000,0.000324)(10000000,0.004057)(100000000,0.040353)(1000000000,0.428903)(10000000000,4.614751)(100000000000,46.221847)(1000000000000,462.256123)};
        \addlegendentry{Taco Dense};
    \end{loglogaxis}
\end{tikzpicture}
\end{subfigure}
\caption{This is the plot for Sparse vs Dense implementations with a sparsity of 95\% and 99\%}
\label{plot:SparseVSDense}
\end{figure}

\end{document}

这不应该看起来像这样: 失败

答案1

您的图太宽,并且您没有加载任何提供subfigure环境的包。一旦解决了这个问题,就可以

\documentclass[11pt,a4paper,bibtotoc,idxtotoc,headsepline,footsepline,footexclude,BCOR12mm,DIV13]{scrbook}
\usepackage{subcaption}
\usepackage{pgfplots} 
\pgfplotsset{compat=1.16}
\begin{document}
\begin{figure}
\centering
\begin{subfigure}[b]{0.48\textwidth}
\begin{tikzpicture}
    \begin{loglogaxis}[legend pos=north west,width=0.99\textwidth]
        \addplot coordinates {(1000000,0.000043)(10000000,0.000208)(100000000,0.001435)(1000000000,0.024813)(10000000000,0.052237)(100000000000,0.392075)(1000000000000,7.640320)};
        \addlegendentry{Eigen Sparse};
        \addplot coordinates {(1000000,0.000038)(10000000,0.000102)(100000000,0.000687)(1000000000,0.004481)(10000000000,0.039102)(100000000000,0.473834)(1000000000000,4.163624)};
        \addlegendentry{Eigen Dense};
        \addplot coordinates {(1000000,0.000250)(10000000,0.002253)(100000000,0.023046)(1000000000,0.226521)(10000000000,2.256439)(100000000000,22.539281)(1000000000000,228.897577)};
        \addlegendentry{Taco Sparse};
        \addplot coordinates {(1000000,0.000164)(10000000,0.001970)(100000000,0.019437)(1000000000,0.193552)(10000000000,2.324910)(100000000000,22.873258)(1000000000000,228.062183)};
        \addlegendentry{Taco Dense};
    \end{loglogaxis}
\end{tikzpicture}
\end{subfigure}~
\begin{subfigure}[b]{0.48\textwidth}
\begin{tikzpicture}
    \begin{loglogaxis}[legend pos = north west,width=0.99\textwidth]
        \addplot coordinates {(1000000,0.000006)(10000000,0.000021)(100000000,0.000191)(1000000000,0.001376)(10000000000,0.014545)(100000000000,0.152963)(1000000000000,3.680731)};
        \addlegendentry{Eigen Sparse};
        \addplot coordinates {(1000000,0.000037)(10000000,0.000126)(100000000,0.001479)(1000000000,0.012454)(10000000000,0.085147)(100000000000,1.099040)(1000000000000,9.001991)};
        \addlegendentry{Eigen Dense};
        \addplot coordinates {(1000000,0.000066)(10000000,0.000474)(100000000,0.004661)(1000000000,0.047827)(10000000000,0.448608)(100000000000,4.491783)(1000000000000,47.770237)};
        \addlegendentry{Taco Sparse};
        \addplot coordinates {(1000000,0.000324)(10000000,0.004057)(100000000,0.040353)(1000000000,0.428903)(10000000000,4.614751)(100000000000,46.221847)(1000000000000,462.256123)};
        \addlegendentry{Taco Dense};
    \end{loglogaxis}
\end{tikzpicture}
\end{subfigure}
\caption{This is the plot for Sparse vs Dense implementations with a sparsity of 95\% and 99\%}
\label{plot:SparseVSDense}
\end{figure}
\end{document}

在此处输入图片描述

这假设您最终想要为子图添加标题。如果不是,或者您想为它们添加标题,您可能需要使用该groupplots库。

相关内容