0

I am trying to plot the following figure with 4 sub-plots. The first figure shows the kind of plot which I want to get corrected. The corrections are marked with questions. I tried an answer from a previous post, and the code is shown below.

The result of which is shown in the result section. But the problem with alignment of sub-figures and labels still persist. Can someone suggest the changes in my code, which can result in a better and meaningful figure.

Correction required:

enter image description here

Result:

enter image description here

Code:

\documentclass[12pt, a4paper,
                parskip=half,
                toc=bibliography,
                numbers=noendperiod
               ]{scrbook}

\usepackage[hmargin={3.0cm, 2.5cm}, vmargin={2.5cm, 2.0cm}, includehead, includefoot ]{geometry}

\usepackage[UKenglish]{babel} \usepackage[T1]{fontenc}

\usepackage{scrlayer-scrpage} \usepackage{subcaption} \usepackage{caption} \addtokomafont{caption}{\scriptsize} \setkomafont{captionlabel}{\bfseries\rmfamily}

\usepackage[dvipsnames,table,xcdraw]{xcolor} \usepackage{pgfplots} \pgfplotsset{compat=1.18}

\begin{document} \begin{figure}[ht] \pgfplotsset{ width=\linewidth, height=0.75\linewidth, enlarge y limits=0.1, %tick label style={font=\scriptsize}, %xticklabel style = {text width=0.4em}, %ylabel style = {text width=1em, inner sep=2pt}, %yticklabel style = {text width=0.2em}, %label style={font=\bfseries\boldmath}, %tick label style={font=\bfseries\boldmath}, % %tick align = outside, %tick pos = left, %every axis plot post/.append style={color=Blue, dashed, mark=}, } \begin{subfigure}[t]{0.48\linewidth} \begin{tikzpicture} \begin{loglogaxis}[ xmin=0.1, xmax=0.1e8, ymin=1e-8, ymax=5e3, xlabel={Number of Flops}, ylabel={Normalized MSE: $\log_{10} (e)$ }, scatter/classes={ a={mark=square, blue}, b={mark=square, red}, c={mark=square, black}, d={mark=triangle, blue}, e={mark=triangle, red},f={mark=triangle, black},g={mark=x, black}, h={mark= diamond, pink} }, ] \addplot[scatter, only marks, scatter src=explicit symbolic] table[meta=label] { x y label 1320.9279232530525 0.9258769833615981 a 3102.831857215906 0.7072210955836371 a }; \end{loglogaxis} \end{tikzpicture} \caption{Plot 1} \end{subfigure} \hfill \begin{subfigure}[t]{0.48\linewidth} \begin{tikzpicture} \begin{axis}[ domain=0:1, ymax=1, xlabel={Input $x$}, ylabel={$f(x)$}, %samples=801 ] \addplot {sin(5deg(x))}; \addplot {sin(10*deg(x))}; \legend{$\sin(5x)$,$\sin(10x)$,$\sin(50x)$} \end{axis} \end{tikzpicture} \caption{Plot 2} \end{subfigure}

        \medskip
            \begin{subfigure}[t]{0.48\linewidth}
                \begin{tikzpicture}
                    \begin{loglogaxis}[
                    xmin=0.1, xmax=0.1e8,
                    ymin=1e-13, ymax=5e3,
                    xlabel={Number of Flops}, 
                    ylabel={Normalized MSE: $\log_{10} (e)$ },
                    %label style={font=\bfseries\boldmath},
                    %tick label style={font=\bfseries\boldmath},
                    scatter/classes={ a={mark=square*, blue}, b={mark=square*, red}, c={mark=square, black}, d={mark=triangle*, blue}, e={mark=triangle*, red},f={mark=triangle*, black},g={mark=x, black}, h={mark= diamond*, pink} },
                    ] 
                        \addplot[scatter, only marks,
                        scatter src=explicit symbolic]
                            table[meta=label] {
                            x     y      label
                            55.57063517556737 0.28272347338878956 a
                            285.8811806506138 0.003443221651312178 a

                            };                        
                    \end{loglogaxis}
                \end{tikzpicture}
                \caption{Plot 3}
            \end{subfigure}
        \hfill
            \begin{subfigure}[t]{0.48\linewidth}
                \begin{tikzpicture}
                    \begin{axis}[
                        xlabel={Input $x$}, 
                        ylabel={$f(x)$},
                        ymin= 0, ymax=1e2,
                                ]
                        \addplot  {e^x)};
                        \addplot  {e^(2*x))};
                        \legend{$\exp(x)$,$\exp(2x)$}
                    \end{axis}
                \end{tikzpicture}
                \caption{Plot 4}
            \end{subfigure}
    \caption{caption for all plots}
    \label{all_plots}
\end{figure}

\end{document}


New updates:

Updated figure

enter image description here

Updated code:

\documentclass[12pt, a4paper,
                parskip=half,
                toc=bibliography,
                numbers=noendperiod
               ]{scrbook}

\usepackage[hmargin={3.0cm, 2.5cm}, vmargin={2.5cm, 2.0cm}, includehead, includefoot ]{geometry}

\usepackage[UKenglish]{babel} \usepackage[T1]{fontenc}

\usepackage{scrlayer-scrpage} \usepackage{subcaption} \usepackage{caption}

\setkomafont{captionlabel}{\bfseries\rmfamily}

\usepackage[dvipsnames,table,xcdraw]{xcolor} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \usepackage[font=normalsize]{subcaption}

\begin{document} \begin{figure}[ht] \pgfplotsset{ width=\linewidth, height=0.9\linewidth, enlarge y limits=0.1, %tick label style={font=\scriptsize}, xticklabel style = {text width=0.8em}, %ylabel style = {text width=1em, inner sep=2pt}, yticklabel style = {text width=2.0em, anchor= east}, label style={font=\bfseries\boldmath}, %tick label style={font=\bfseries\boldmath}, % %tick align = outside, tick pos = left, %every axis plot post/.append style={color=Blue, dashed, mark=}, } \begin{subfigure}[t]{0.48\linewidth} \begin{tikzpicture} \begin{loglogaxis}[ xmin=10, xmax=0.1e8, ymin=1e-8, ymax=1e2, xlabel={Number of Flops}, ylabel={Normalized MSE: $\log_{10} (e)$ }, scatter/classes={ a={mark=square, blue}, b={mark=square, red}, c={mark=square, black}, d={mark=triangle, blue}, e={mark=triangle, red},f={mark=triangle, black},g={mark=x, black}, h={mark= diamond*, pink} }, ] \addplot[scatter, only marks, scatter src=explicit symbolic] table[meta=label] { x y label 1320.9279232530525 0.9258769833615981 a

                                };
                        \end{loglogaxis}
                    \end{tikzpicture}
                \caption{Plot 1}
            \end{subfigure}
        \hfill
            \begin{subfigure}[t]{0.48\linewidth}
                \begin{tikzpicture}
                    \begin{axis}[
                        domain=0:1,
                        ymax=1,
                        xlabel={Input $x$},
                        ylabel={$f(x)$},
                        %samples=801
                                ]
                        \addplot[orange, mark=*] {sin(5*deg(x))};
                        \addplot[black, mark=*] {sin(10*deg(x))};
                        \legend{$\sin(5x)$,$\sin(10x)$,$\sin(50x)$}
                    \end{axis}
                \end{tikzpicture}
                \caption{Plot 2}
            \end{subfigure}

        \medskip
            \begin{subfigure}[t]{0.48\linewidth}
                \begin{tikzpicture}
                    \begin{loglogaxis}[
                    xmin=10, xmax=0.1e8,
                    ymin=1e-13, ymax=1e1,
                    xlabel={Number of Flops}, 
                    ylabel={Normalized MSE: $\log_{10} (e)$ },
                    %label style={font=\bfseries\boldmath},
                    %tick label style={font=\bfseries\boldmath},
                    scatter/classes={ a={mark=square*, blue}, b={mark=square*, red}, c={mark=square, black}, d={mark=triangle*, blue}, e={mark=triangle*, red},f={mark=triangle*, black},g={mark=x, black}, h={mark= diamond*, pink} },
                    ] 
                        \addplot[scatter, only marks,
                        scatter src=explicit symbolic]
                            table[meta=label] {
                                x     y      label
                                55.57063517556737 0.28272347338878956 a

                                };                        
                    \end{loglogaxis}
                \end{tikzpicture}
                \caption{Plot 3}
            \end{subfigure}
        \hfill
            \begin{subfigure}[t]{0.48\linewidth}
                \begin{tikzpicture}
                    \begin{axis}[
                        domain=0:1,
                        xlabel={Input $x$}, 
                        ylabel={$f(x)$},
                        ymin= 0, ymax=1e1,
                                ]
                        \addplot[orange, mark=*]  {e^x)};
                        \addplot[black, mark=*]  {e^(2*x))};
                        \legend{$\exp(x)$,$\exp(2x)$}
                    \end{axis}
                \end{tikzpicture}
                \caption{Plot 4}
            \end{subfigure}
    \caption{caption for all plots}
    \label{all_plots}
\end{figure}

\end{document}

  • 1
    Is this a re-post? // Still my analysis made in this comment holds: https://tex.stackexchange.com/questions/691966/align-tikzpicture-plots-subfigures-horizontally-and-vertically#comment1717091_691966, while Zarko turned it into a solution. – MS-SPO Aug 02 '23 at 07:28
  • 1
    @MS-SPO Yes, that original post had a lot of unnecessary details which I thought should be edited out. Hence I deleted that and created a better post. Thanks for the help. You can see I have implemented your solution as well. But that was still having the same problems. – Formal_this Aug 02 '23 at 13:47

1 Answers1

2

Not a complete answer, but too long for a comment. Some of these bullet points refer to an older version of the question.

Preliminary comments

  • Please note that I get a "dimension too large" error when compiling your code as is.
  • I, and probably other people working with your code, would be happy to have properly indented code as it is much easier to read.

Why do these issues arise?

  • First of all, you set width and height. I read (e.g. pgfplots Figure with fixed Width) that pgfplots only estimates the size, therefore some inaccuracies are possible.
  • The rotated ylabel: You specified trig format = rad. Therefore the ylabel is not rotated by 90° (degree), but by 90 (radians), which is equivalent to approximately 117° -- the angle of your label.
  • Vertical alignment in first row: Your xlabels and xticklabels seem to have a different font size and series. In addition, the left xticklabels have exponents, whereas the right ones don't. Therefore the xticklabels of the left plot are higher and need more space, so they shift the plot upwards.
  • Vertical alignment in second row: In addition to the previous point, you omitted the xtick(label)s completely, so the plot is not pushed upwards.
  • Horizontal alignment left column: The exponents in the upper plot have a sign and two digits, while the lower ones have a sign and one digit.
  • Horizontal alignment right column: The yticklabels in the upper plot do have a sign, whereas the ones in the lower plot don't.
New bullet points
  • For me, the dimensions too large error persits. In your bottom right plot, the domain is probably [-5, 5], i.e. the red plot attains the value e^(2*5). This value is too large for TeX.
  • \addtokomafont{caption}{\scriptsize} sets captions in scriptsize.
Very new bullet point
  • Misaligned yticklabels: As soon as you set yticklabel style = {text width=2.0em}, the yticklabels become left aligned.

How to resolve the issues

  • The rotated ylabel: It can be solved easily: omit trig format = rad and use \addplot {sin(5*deg(x))}; instead of \addplot {sin(5*x)};.
  • Vertical alignment in second row: Add xtick(label)s. Why would you omit them?
New bullet points
  • Dimensions too large error: You can avoid it by using \addplot[domain=-5:2.3] {e^(2*x))}; in your bottom right plot (note that e^(2*2.3) \approx 1e2).
  • Caption font size: Commenting the line mentioned above sets them at least to size 11, but not yet to size 12 like your default font size. Therefore use \usepackage[font=normalsize]{subcaption}.
Very new bullet point
  • Misaligned yticklabels: Use yticklabel style = {text width=2.0em, align=right} instead. The anchor is unrelated to the problem.

For the others I currently don't have an answer.

Other comments

  • Please use math mode for math expressions, i.e. xlabel={$x$} instead of xlabel={x}.
  • Don't use different font (attributes) in your subplots.
Οὖτις
  • 2,897
  • 1
  • 5
  • 18
  • Thanks for the advice on code correction, I have updated the code and now it should compile without errors. – Formal_this Aug 02 '23 at 13:59
  • Hey, I followed all your advice, and the plots are actually looking better already. Thanks. Now my questions are about the font in the caption, which looks pretty different, how to change them? The figures can be aligned better. and the right plots have markers which are way too big, can we make them smaller? – Formal_this Aug 02 '23 at 14:56
  • 1
    @Formal_this please see my updated answer. – Οὖτις Aug 03 '23 at 16:43
  • Hi, that makes sense. I updated my question. The only problem now remains is, the tick labels are not aligning with the axis, but they are sort of differently aligned. As marked by the red vertical line. Can you suggest something. Thanks. – Formal_this Aug 03 '23 at 21:31
  • 1
    @Formal_this please see again my updated answer. I just googled the issue and found https://tex.stackexchange.com/a/195482/237192 – Οὖτις Aug 06 '23 at 14:42
  • Thanks, that makes sense. Also, can you check whether we can adjust dimension of asymptotic functions in subfigures. I posted my doubt in this link: https://tex.stackexchange.com/questions/692591/how-to-plot-a-custom-bessel-function?noredirect=1#comment1718863_692591 – Formal_this Aug 06 '23 at 15:42