我尝试从通过 matlab2tikz 自动生成的文件“aLinePlot.tex”中绘制一条线:
% 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.951\fwidth,
height=0.75\fwidth,
at={(0\fwidth,0\fwidth)},
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}%
使用以下最小示例,我收到错误“未定义的控制序列。\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}
\newlength\fwidth
\newlength\fheight % not used in this example
\begin{document}
\begin{figure}[htb]
\begin{center}
\setlength{\fwidth}{.7\linewidth}
\input{aLinePlot.tex}
\label{fig:someLabel}
\caption{some Caption}
\end{center}
\end{figure}
\end{document}
由于我对 tikz 不太熟悉,有人能给我提示如何解决这个问题吗?顺便说一句:编译器是 Linux 机器上的 PdfLatex
答案1
您的编辑器在解析文件时没有帮助您.log
,错误显示
! Undefined control sequence.
\tikz@textfont ->\miniscule
l.73 \end{axis}
?
这意味着这\miniscule
是未定义的控制序列。
\miniscule
是标准类中未定义的字体大小开关,但它在memoir
类中定义。因此,要么将 documentclass 更改为memoir
,要么修改
legend style={font=\miniscule}
例如
legend style={font=\tiny}
工作代码:
\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}
\newlength\fwidth
\newlength\fheight % not used in this example
\begin{document}
\begin{figure}[htb]
\begin{center}
\setlength{\fwidth}{.7\linewidth}
% 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.951\fwidth,
height=0.75\fwidth,
at={(0\fwidth,0\fwidth)},
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}
答案2
\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.951\figW,
height=\figH,
at={(0\figW,0\figH)},
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}