Search code examples
latexsyntax-errormatlab-figure

matlab2tikz figure shown in next page error


I have over my thesis work this repeated problem, in which after converting the image through matlab2tikz, the figure is showned in the next page. An example is PageError

The code to call this is:

\subsection{Signal Phi Card Visualization}
In comparison with...

\begin{figure}[hb!]
    \centering
    \input{imagesMatlab/phiCardNew.tex}
    \caption{R peak Detection for each capacitive ECG, in comparison with the reference ECG}
    \label{fig:phi card new example}

\end{figure}

\clearpage

And the code within the figure is:

% This file was created by matlab2tikz.
%
%The latest updates can be retrieved from
%  http://www.mathworks.com/matlabcentral/fileexchange/22022-matlab2tikz-matlab2tikz
%where you can also make suggestions and rate matlab2tikz.
%
\definecolor{mycolor1}{rgb}{0.00000,0.44700,0.74100}%
\definecolor{mycolor2}{rgb}{0.85000,0.32500,0.09800}%
\definecolor{mycolor3}{rgb}{0.92900,0.69400,0.12500}%
\definecolor{mycolor4}{rgb}{0.49400,0.18400,0.55600}%
\definecolor{mycolor5}{rgb}{0.46600,0.67400,0.18800}%
\definecolor{mycolor6}{rgb}{0.30100,0.74500,0.93300}%
\definecolor{mycolor7}{rgb}{0.63500,0.07800,0.18400}%
%
\begin{tikzpicture}

\begin{axis}[%
width=.8\textwidth,
height=.4\textheight,
at={(0in,9in)},
scale only axis,
xmin=0,
xmax=1035.59707636169,
ymin=-3.5,
ymax=3.5,
axis background/.style={fill=white},
axis x line*=bottom,
axis y line*=left
xlabel style={font=\color{white!15!black}},
xlabel={Samples},
ylabel style={font=\color{white!15!black}},
ylabel={Voltage [mV]},
]
\addplot [color=mycolor1, forget plot]
  table[row sep=crcr]{%
0   -3.14159265358978\\
197 3.14159265358978\\
};
\addplot [color=mycolor2, forget plot]
  table[row sep=crcr]{%
197 3.14159000000001\\
198 -3.14159000000001\\
};
\addplot [color=mycolor3, forget plot]
  table[row sep=crcr]{%
198 -3.14159265358978\\
314 3.14159265358978\\
};
\addplot [color=mycolor4, forget plot]
  table[row sep=crcr]{%
314 3.14159000000001\\
315 -3.14159000000001\\
};
\addplot [color=mycolor5, forget plot]
  table[row sep=crcr]{%
315 -3.14159265358978\\
537 3.14159265358978\\
};
\addplot [color=mycolor6, forget plot]
  table[row sep=crcr]{%
537 3.14158999999995\\
538 -3.14158999999995\\
};
\addplot [color=mycolor7, forget plot]
  table[row sep=crcr]{%
538 -3.14159265358978\\
705 3.14159265358978\\
};
\addplot [color=mycolor1, forget plot]
  table[row sep=crcr]{%
705 3.14158999999995\\
706 -3.14158999999995\\
};
\addplot [color=mycolor2, forget plot]
  table[row sep=crcr]{%
706 -3.14159265358978\\
822 3.14159265358978\\
};
\addplot [color=mycolor3, forget plot]
  table[row sep=crcr]{%
822 3.14158999999995\\
823 -3.14158999999995\\
};
\addplot [color=mycolor4, forget plot]
  table[row sep=crcr]{%
823 -3.14159265358978\\
1002    3.14159265358978\\
};
\addplot [color=mycolor5, forget plot]
  table[row sep=crcr]{%
1002    3.14158999999995\\
1003    -3.14158999999995\\
};
\addplot [color=mycolor6, forget plot]
  table[row sep=crcr]{%
1003    -3.1415926535899\\
1036    -1.08867072154112\\
};
\end{axis}

\begin{axis}[%
width=16.286in,
height=10.113in,
at={(0in,0in)},
scale only axis,
xmin=0,
xmax=1,
ymin=0,
ymax=1,
axis line style={draw=none},
ticks=none,
axis x line*=bottom,
axis y line*=left
]
\end{axis}
\end{tikzpicture}%

I tried to understand the block [htb!] %here, top, bottom but there´s still something unclear for me here. I thought also the position could be change with the command at={...} but the answer is the same. Can anyone explain me this?

Thank you, David


Solution

  • Two problems:

    • the comma at the end of the line axis y line*=left is missing. This will cause an error in your log file. There is no point at even looking at the output if there re still errors in the log file. Fix errors first before worrying about such details as page breaks!

    • the second, empty axis environment blows up the image immensely. Just get rid of it. A warning in the log file will inform you about the overfull box. Fix such warnings before worrying about page breaks.


    \documentclass{article}
    
    \usepackage{float}
    \usepackage{pgfplots}
    
     \pgfplotsset{compat=newest}
    
    \begin{document}
    
    \subsection{Signal Phi Card Visualization}
    In comparison with...
    
    \begin{figure}[htbp]
        \centering
        % This file was created by matlab2tikz.
        %
        %The latest updates can be retrieved from
        %  http://www.mathworks.com/matlabcentral/fileexchange/22022-matlab2tikz-matlab2tikz
        %where you can also make suggestions and rate matlab2tikz.
        %
        \definecolor{mycolor1}{rgb}{0.00000,0.44700,0.74100}%
        \definecolor{mycolor2}{rgb}{0.85000,0.32500,0.09800}%
        \definecolor{mycolor3}{rgb}{0.92900,0.69400,0.12500}%
        \definecolor{mycolor4}{rgb}{0.49400,0.18400,0.55600}%
        \definecolor{mycolor5}{rgb}{0.46600,0.67400,0.18800}%
        \definecolor{mycolor6}{rgb}{0.30100,0.74500,0.93300}%
        \definecolor{mycolor7}{rgb}{0.63500,0.07800,0.18400}%
        %
        \begin{tikzpicture}
        
        \begin{axis}[%
        width=.8\textwidth,
        height=.4\textheight,
    %    at={(0in,9in)},
        scale only axis,
        xmin=0,
        xmax=1035.59707636169,
        ymin=-3.5,
        ymax=3.5,
        axis background/.style={fill=white},
        axis x line*=bottom,
        axis y line*=left,
        xlabel style={font=\color{white!15!black}},
        xlabel={Samples},
        ylabel style={font=\color{white!15!black}},
        ylabel={Voltage [mV]},
        ]
        \addplot [color=mycolor1, forget plot]
          table[row sep=crcr]{%
        0   -3.14159265358978\\
        197 3.14159265358978\\
        };
        \addplot [color=mycolor2, forget plot]
          table[row sep=crcr]{%
        197 3.14159000000001\\
        198 -3.14159000000001\\
        };
        \addplot [color=mycolor3, forget plot]
          table[row sep=crcr]{%
        198 -3.14159265358978\\
        314 3.14159265358978\\
        };
        \addplot [color=mycolor4, forget plot]
          table[row sep=crcr]{%
        314 3.14159000000001\\
        315 -3.14159000000001\\
        };
        \addplot [color=mycolor5, forget plot]
          table[row sep=crcr]{%
        315 -3.14159265358978\\
        537 3.14159265358978\\
        };
        \addplot [color=mycolor6, forget plot]
          table[row sep=crcr]{%
        537 3.14158999999995\\
        538 -3.14158999999995\\
        };
        \addplot [color=mycolor7, forget plot]
          table[row sep=crcr]{%
        538 -3.14159265358978\\
        705 3.14159265358978\\
        };
        \addplot [color=mycolor1, forget plot]
          table[row sep=crcr]{%
        705 3.14158999999995\\
        706 -3.14158999999995\\
        };
        \addplot [color=mycolor2, forget plot]
          table[row sep=crcr]{%
        706 -3.14159265358978\\
        822 3.14159265358978\\
        };
        \addplot [color=mycolor3, forget plot]
          table[row sep=crcr]{%
        822 3.14158999999995\\
        823 -3.14158999999995\\
        };
        \addplot [color=mycolor4, forget plot]
          table[row sep=crcr]{%
        823 -3.14159265358978\\
        1002    3.14159265358978\\
        };
        \addplot [color=mycolor5, forget plot]
          table[row sep=crcr]{%
        1002    3.14158999999995\\
        1003    -3.14158999999995\\
        };
        \addplot [color=mycolor6, forget plot]
          table[row sep=crcr]{%
        1003    -3.1415926535899\\
        1036    -1.08867072154112\\
        };
        \end{axis}
        
    %    \begin{axis}[%
    %%    width=16.286in,
    %%    height=10.113in,
    %%    at={(0in,0in)},
    %    scale only axis,
    %    xmin=0,
    %    xmax=1,
    %    ymin=0,
    %    ymax=1,
    %    axis line style={draw=none},
    %    ticks=none,
    %    axis x line*=bottom,
    %    axis y line*=left
    %    ]
    %    \end{axis}
        \end{tikzpicture}%
        \caption{R peak Detection for each capacitive ECG, in comparison with the reference ECG}
        \label{fig:phi card new example}
    \end{figure}
    
    \clearpage
    
    
    
    \end{document}
    

    enter image description here