2

How can i get two tikzpictures in one figure using subfigure and scale them down a bit such that they fit the page? If it fits anyways, not downscaling needs to be done.

\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}

This should not look like this: fail

1 Answer 1

4

Your figure is to wide and you didn't load any package that provides a subfigure environment. Once one fixes this, one gets

\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}

enter image description here

This assumes you want eventually to give the subfigures captions. If not, or if you want to give them titles instead, you may want to use the groupplots library.

3
  • Sry, subcaptions is used, i just forgot to add it. Commented May 9, 2019 at 13:51
  • And by the way, it now works perfectly. Thank you a lot Commented May 9, 2019 at 13:53
  • @CleboSevic You're welcome!
    – user121799
    Commented May 9, 2019 at 13:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .