1

I'm getting the "Package tikz Error: Giving up on this path. Did you forget a semicolon?" error, but I don't see any semicolon missing and the diagram displays as intended. I guess I just don't understand the code well enough, could anyone help me figure out the mistake?

Here's the code:

    \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 Answer 1

4

When you use the (x,y) syntax you must pay attention to inner parentheses and protect them. E.g. for the first plot add braces around the second argument:

        \addplot[samples=100,blue,domain=-10:10] ( x , {sqrt(1 + x^2)} );

instead of

        \addplot[samples=100,blue,domain=-10:10] ( x , sqrt(1 + x^2) );

To quote the documentation:

Note further that since the complete point expression is surrounded by round braces, round braces for either <x expression> or <y expression> need special attention. You will need to introduce curly braces additionally to allow round braces:

1
  • That solved it, thanks for the answer! I always forget where the curly braces are necessary. Sep 28, 2019 at 9:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .