我收到“Package tikz 错误:放弃此路径。您是否忘记了分号?”错误,但我没有看到任何缺少的分号,并且图表按预期显示。我想我只是对代码理解不够好,有人能帮我找出错误吗?
代码如下:
\documentclass{report}
\usepackage{amsthm}
\usepackage{pgfplots} %Plots with tikz
\pgfplotsset{compat=newest}
\usepackage{float}
\begin{document}
\begin{figure}[H]
\centering
\begin{tikzpicture}
\begin{axis}[
height=8cm, width=8cm,
axis y line=center, axis x line=center,
ylabel={$ct$}, xlabel={$x^1$},
every axis y label/.style={ at={(ticklabel* cs:1.05)},anchor=south,},
every axis x label/.style={ at={(ticklabel* cs:1.05)},anchor=west,}, no marks, ticks={none}, xmin=-8,xmax=8,ymin=-8,ymax=8,
legend style={at={(axis cs:8.3,4)},anchor=south west},
]
\addplot[samples=100,blue,domain=-10:10] ( x , sqrt(1 + x^2) );
\addlegendentry{$s^2 > 0$};
\addplot[samples=100,red,domain=-10:10] (sqrt(1 + x^2) , x );
\addlegendentry{$s^2 < 0$};
\addplot[thick,domain=-10:10] {x};
\addplot[thick,domain=-10:10] {-x};
\addlegendentry{$s^2 = 0$};
\addplot[samples=100,blue,domain=-10:10] ( x , sqrt(8 + x^2) );
\addplot[samples=100,blue,domain=-10:10] ( x , sqrt(20 + x^2) );
\addplot[samples=100,blue,domain=-10:10] ( x , sqrt(35 + x^2) );
\addplot[samples=100,blue,domain=-10:10] ( x , sqrt(55 + x^2) );
\addplot[samples=100,blue,domain=-10:10] ( x , -sqrt(1 + x^2) );
\addplot[samples=100,blue,domain=-10:10] ( x , -sqrt(8 + x^2) );
\addplot[samples=100,blue,domain=-10:10] ( x , -sqrt(20 + x^2) );
\addplot[samples=100,blue,domain=-10:10] ( x , -sqrt(35 + x^2) );
\addplot[samples=100,blue,domain=-10:10] ( x , -sqrt(55 + x^2) );
\addplot[samples=100,red,domain=-10:10] (sqrt(8 + x^2) , x );
\addplot[samples=100,red,domain=-10:10] (sqrt(20 + x^2) , x );
\addplot[samples=100,red,domain=-10:10] (sqrt(35 + x^2) , x );
\addplot[samples=100,red,domain=-10:10] (sqrt(55 + x^2) , x );
\addplot[samples=100,red,domain=-10:10] (-sqrt(1 + x^2) , x );
\addplot[samples=100,red,domain=-10:10] (-sqrt(8 + x^2) , x );
\addplot[samples=100,red,domain=-10:10] (-sqrt(20 + x^2) , x );
\addplot[samples=100,red,domain=-10:10] (-sqrt(35 + x^2) , x );
\addplot[samples=100,red,domain=-10:10] (-sqrt(55 + x^2) , x );
\draw [black, draw=black, fill=cyan, opacity=0.1] (0,0) -- (10,10) -- (-10,10) -- cycle;
\draw [black, draw=black, fill=cyan, opacity=0.1] (0,0) -- (10,-10) -- (-10,-10) -- cycle;
\draw [black, draw=black, fill=purple, opacity=0.1] (0,0) -- (-10,10) -- (-10,-10) -- cycle;
\draw [black, draw=black, fill=purple, opacity=0.1] (0,0) -- (10,10) -- (10,-10) -- cycle;
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
答案1
使用(x,y)
语法时,必须注意内括号并保护它们。例如,对于第一个图,在第二个参数周围添加括号:
\addplot[samples=100,blue,domain=-10:10] ( x , {sqrt(1 + x^2)} );
代替
\addplot[samples=100,blue,domain=-10:10] ( x , sqrt(1 + x^2) );
引用文档:
<x expression>
还要注意,由于完整的点表达式被圆括号包围,因此或的圆括号<y expression>
需要特别注意。您需要另外引入花括号才能使用圆括号: