我一直在使用 pgfplots 来生成建模课程作业中的图像。我收到了下面的错误,但似乎无法在我的代码中找到它。
Missing character: There is no ; in font nullfont!
Missing character: There is no ; in font nullfont!
Package pgfplots info on input line 73: fill between: found 'clip=true'. Prepar
ing pgfplotsextra instruction with clip path for layer 'pre main'...
Package pgfplots info on input line 75: fill between: activating layered graphi
cs
\pgf@layerbox@axis background=\box60
\pgf@layerboxsaved@axis background=\box61
\pgf@layerbox@axis grid=\box62
\pgf@layerboxsaved@axis grid=\box63
\pgf@layerbox@axis ticks=\box64
\pgf@layerboxsaved@axis ticks=\box65
\pgf@layerbox@axis lines=\box66
\pgf@layerboxsaved@axis lines=\box67
\pgf@layerbox@axis tick labels=\box68
\pgf@layerboxsaved@axis tick labels=\box69
\pgf@layerbox@pre main=\box70
\pgf@layerboxsaved@pre main=\box71
\pgf@layerbox@axis descriptions=\box72
\pgf@layerboxsaved@axis descriptions=\box73
\pgf@layerbox@axis foreground=\box74
\pgf@layerboxsaved@axis foreground=\box75
Package pgfplots info on input line 75: Setting layers 'axis background,axis gr
id,axis ticks,axis lines,axis tick labels,pre main,main,axis descriptions,axis
foreground'...
./untitled.tex:75: Missing { inserted.
<to be read again>
$
l.75 \end{axis}
A left brace was mandatory here, so I've put one in.
You might want to delete and/or insert some corrections
so that I will find a matching right brace soon.
(If you're confused by all this, try typing `I}' now.)
./untitled.tex:75: Missing } inserted.
<inserted text>
}
l.75 \end{axis}
I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.
这是产生错误的 MWE。我的图结果很好,但我对编译错误不满意。
\documentclass[fontsize=12pt,parskip=half*,oneside,paper=letter]{scrartcl}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage[hyperindex,setpagesize=false,pdfstartview=Fit]{hyperref}
\usepackage{asymptote}
\usepackage{tikz}
\usepackage[top=1.25in,bottom=1in,left=1in,right=1.25in]{geometry}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{booktabs}
\usepackage{pgfplotstable,pgfplots}
\usepackage{enumitem}
\usepackage{ifpdf}
\usepackage{bbm}
\usetikzlibrary{scopes,calc,patterns}
\usepgfplotslibrary{fillbetween}
\usepackage{fontspec}
\setmainfont[ItalicFont={Gill Sans Italic}]{Minion Pro}
\ifpdf\usepackage[linkcolor=blue,pdfborderstyle={/S/U/W 1},hyperfootnotes=true]{hyperref}\fi
\newcommand*{\E}{\mathbbm{e}}
\pgfplotstableread{
S_t R_t+2 R^ R^+ R^- Resid R_t+2 t
694.5250866 2189.100077 1923.359077 2328.022827 1923.77735 2052.424701 2395.342679 2480.683342
1413.385962 5890.33904 3777.200816 4564.31122 3778.015365 3951.711315 4704.10878 4391.013507
1484.115908 5609.424882 3952.352559 4775.181068 3953.204171 4127.583746 4922.241967 3749.410756
1573.08642 8365.224824 4170.86977 5038.154433 4171.767526 4346.195106 5194.382312 5917.141295
1701.821077 9425.686222 4483.516634 5414.201194 4484.480224 4657.459338 5583.7513 8990.504917
}{\conf}
\begin{document}
\begin{tikzpicture}[scale=1,baseline]
\begin{axis}[align=center,
xlabel={Year},
legend cell align=right,
legend pos = outer north east,
%legend style={at={(0.5,-0.25)},anchor=north,draw=none},
/pgf/number format/1000 sep={}]
\makeatletter
\addplot table [x=t,y=R_t+2] {\conf};
\addlegendentry{Residuals for $\ln(R)$ vs $\ln(R)^{\wedge}$}
\draw[ultra thin] (axis cs:\pgfkeysvalueof{/pgfplots/xmin},0) -- (axis cs:\pgfkeysvalueof{/pgfplots/xmax},0);
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[scale=1.75,
%align=center,
title={Mean-unbiased estimate\\ with 95\% confidence interval},
xlabel={Year},
legend cell align=right,
legend pos = outer north east,
%legend style={at={(0.5,-0.25)},anchor=north,draw=none},
/pgf/number format/1000 sep={}]
\addplot table [x=S_t,y={R^}] {\conf};
\addlegendentry{Predicted $R^$};
\addplot table [x=S_t,y={R_t+2}, only marks] {\conf};
\addlegendentry {Actual $R$};
\addplot [name path = top] table [y={R^+}, x=S_t] {\conf} \closedcycle;
\addplot [name path = bottom] table [y={R^-}, x=S_t] {\conf} \closedcycle;
\addplot+ fill between [of=top and bottom, every segment no 0/.style={pattern color = blue, opacity=.35}];
%\draw[ultra thin] (axis cs:\pgfkeysvalueof{/pgfplots/xmin},0) -- (axis cs:\pgfkeysvalueof{/pgfplots/xmax},0);
\end{axis}
\end{tikzpicture}
\end{document}
答案1
虽然R^
可以用作表格的标题\pgfplotstableread
,但在 TeX 公式中它是不合法的;你的行
\addlegendentry{Predicted $R^$};
存在导致错误的(TeX 端)语法错误Missing { inserted
。
当 TeX^
在数学模式下发现 时,它希望看到后面有一个可以用作上标或左括号的标记。1在这种情况下,后面的标记^
是$
,这肯定是无效的。 因此 TeX 进入错误恢复并添加 只是{
为了意识到后面的标记是,所以它会尝试再次同步$
插入丢失的发现本身。}
1左括号可以是显式的 ( {
) 也可以是隐式的 ( \bgroup
)。