TransWikia.com

Tikz error with simple Lineplot with legend

TeX - LaTeX Asked by JoeBroesel on March 12, 2021

I try to plot a line from the file “aLinePlot.tex” which is automatically generated via matlab2tikz:

% 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}%
%
begin{tikzpicture}

begin{axis}[%
width=0.951fwidth,
height=0.75fwidth,
at={(0fwidth,0fwidth)},
scale only axis,
xmin=1,
xmax=10,
xlabel style={font=color{white!15!black}},
xlabel={xLabel},
ymin=-0.4,
ymax=1.5,
ylabel style={font=color{white!15!black}},
ylabel={yLabel},
axis background/.style={fill=white},
xmajorgrids,
ymajorgrids,
legend style={at={(0.03,0.97)}, anchor=north west, legend cell align=left, align=left, legend plot pos=left, draw=black}
]
addplot [color=black, line width=1.0pt, mark=o, mark options={solid, black}]
  table[row sep=crcr]{%
1   0.05
2   0.1
3   0.15
4   0.2
5   0.25
6   0.3
7   0.35
8   0.4
9   0.45
10  0.5
};
addlegendentry{legend1}

end{axis}
end{tikzpicture}%

With the following minimal Example I get the error “Undefined control sequence. end{axis}

documentclass[10pt,a4paper]{article}
usepackage[latin1]{inputenc}

usepackage{pgfplots}
pgfplotsset{every axis/.append style={
        label style={font=footnotesize },
        label style={font=footnotesize },
        tick label style={font=footnotesize},  
        legend style={font=miniscule},                     
}}

usepackage{tikz}
pgfplotsset{compat=newest}
pgfplotsset{plot coordinates/math parser=false}
newlengthfwidth
newlengthfheight % not used in this example

begin{document}

    begin{figure}[htb]
        begin{center}
            setlength{fwidth}{.7linewidth} 
            input{aLinePlot.tex}
            label{fig:someLabel}
            caption{some Caption}
        end{center}
    end{figure}

end{document}

As i am not really familiar with tikz, can someone give me a hint how to solve this problem?
Btw: Compiler is PdfLatex on a linux machine

2 Answers

Your editor doesn't help you when it parses the .log file, the error says

! Undefined control sequence.
tikz@textfont ->miniscule 

l.73 end{axis}

? 

which means that miniscule is the undefined control sequence.

miniscule is a font size switch that isn't defined in the standard classes, but it is defined in the memoir class. So either change the documentclass to memoir, or modify

legend style={font=miniscule}

to for example

legend style={font=tiny}

Working code:

documentclass[10pt,a4paper]{memoir} % <-- changed article to memoir
usepackage[latin1]{inputenc}

usepackage{pgfplots}
pgfplotsset{every axis/.append style={
        label style={font=footnotesize },
        label style={font=footnotesize },
        tick label style={font=footnotesize},  
        legend style={font=miniscule},                     
}}

usepackage{tikz}
pgfplotsset{compat=newest}
pgfplotsset{plot coordinates/math parser=false}
newlengthfwidth
newlengthfheight % not used in this example

begin{document}

    begin{figure}[htb]
        begin{center}
            setlength{fwidth}{.7linewidth} 
% 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}%
%
begin{tikzpicture}

begin{axis}[%
width=0.951fwidth,
height=0.75fwidth,
at={(0fwidth,0fwidth)},
scale only axis,
xmin=1,
xmax=10,
xlabel style={font=color{white!15!black}},
xlabel={xLabel},
ymin=-0.4,
ymax=1.5,
ylabel style={font=color{white!15!black}},
ylabel={yLabel},
axis background/.style={fill=white},
xmajorgrids,
ymajorgrids,
legend style={at={(0.03,0.97)}, anchor=north west, legend cell align=left, align=left, legend plot pos=left, draw=black}
]
addplot [color=black, line width=1.0pt, mark=o, mark options={solid, black}]
  table[row sep=crcr]{%
1   0.05
2   0.1
3   0.15
4   0.2
5   0.25
6   0.3
7   0.35
8   0.4
9   0.45
10  0.5
};
addlegendentry{legend1}

end{axis}
end{tikzpicture}%
            label{fig:someLabel}
            caption{some Caption}
        end{center}
    end{figure}

end{document}

Correct answer by Torbjørn T. on March 12, 2021

documentclass{article}
usepackage{tikz}
usepackage{pgfplots}
begin{document}
    % This file was created by matlab2tikz.
    %
    definecolor{mycolor1}{rgb}{0.17969,0.54297,0.33984}%
    definecolor{mycolor2}{rgb}{0.00000,0.53125,0.21484}%
    definecolor{mycolor3}{rgb}{0.36719,0.23438,0.59766}%
    definecolor{mycolor4}{rgb}{0.78906,0.00000,0.12500}%
    definecolor{mycolor5}{rgb}{0.52734,0.80469,0.91797}%
    %
    begin{tikzpicture}
        
        begin{axis}[%
            width=0.951figW,
            height=figH,
            at={(0figW,0figH)},
            scale only axis,
            bar shift auto,
            clip=false,
            xmin=0,
            xmax=100,
            xlabel style={font=color{white!15!black}},
            xlabel={Patch Retrieval mAP [%]},
            y dir=reverse,
            ymin=0.6,
            ymax=2.4,
            ytick={1,2},
            yticklabels={{textbackslash{}orb},{textbackslash{}sift}},
            axis background/.style={fill=white},
            xmajorgrids,
            ymajorgrids,
            legend style={legend cell align=left, align=left, draw=white!15!black}
            ]
            addplot[xbar, bar width=0.8, fill=mycolor1, draw=white!20!black, area legend] table[row sep=crcr] {%
                41.9548209460414    2
            };
            addplot[forget plot, color=white!15!black] table[row sep=crcr] {%
                0   0.6
                0   2.4
            };
            addlegendentry{data1}
            
            node[right, align=left]
            at (axis cs:101,2) {41.95%};
            addplot [color=mycolor2, draw=none, mark size=1.5pt, mark=*, mark options={solid, fill=black!60!mycolor2, mycolor2}]
            table[row sep=crcr]{%
                64.7063703472285    2
            };
            addlegendentry{data2}
            
            addplot [color=mycolor3, draw=none, mark size=1.5pt, mark=*, mark options={solid, fill=black!60!mycolor3, mycolor3}]
            table[row sep=crcr]{%
                38.1802387463562    2
            };
            addlegendentry{data3}
            
            addplot [color=mycolor4, draw=none, mark size=1.5pt, mark=*, mark options={solid, fill=black!60!mycolor4, mycolor4}]
            table[row sep=crcr]{%
                22.9778537445396    2
            };
            addlegendentry{data4}
            
            addplot[xbar, bar width=0.8, fill=mycolor5, draw=white!20!black, area legend] table[row sep=crcr] {%
                29.2544208148136    1
            };
            addplot[forget plot, color=white!15!black] table[row sep=crcr] {%
                0   0.6
                0   2.4
            };
            addlegendentry{data5}
            
            node[right, align=left]
            at (axis cs:101,1) {29.25%};
            addplot [color=mycolor2, draw=none, mark size=1.5pt, mark=*, mark options={solid, fill=black!60!mycolor2, mycolor2}]
            table[row sep=crcr]{%
                50.0597027132659    1
            };
            addlegendentry{data6}
            
            addplot [color=mycolor3, draw=none, mark size=1.5pt, mark=*, mark options={solid, fill=black!60!mycolor3, mycolor3}]
            table[row sep=crcr]{%
                24.2959181262745    1
            };
            addlegendentry{data7}
            
            addplot [color=mycolor4, draw=none, mark size=1.5pt, mark=*, mark options={solid, fill=black!60!mycolor4, mycolor4}]
            table[row sep=crcr]{%
                13.4076416049004    1
            };
            addlegendentry{data8}
            
        end{axis}
    end{tikzpicture}%
end{document}

Answered by yangninghua on March 12, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP