\begin 和 \end{axis} 问题

\begin 和 \end{axis} 问题

我收到以下错误信息:

! Missing } inserted.
<inserted text>
}
l.47 \end{axis}

我正在使用最新版本的 Tex。提前致谢!

\documentclass[a4paper,12pt]{article}

\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary {shapes.geometric, arrows}
\usepackage[margin=0.25in]{geometry}
\usepackage{pgfplots}
\pgfplotsset{width=10cm,compat=1.9}

\begin{document}

\begin{tikzpicture}
  \begin{axis}[
    axis equal,
    axis lines=middle,
    xlabel={$x$},
    ylabel={$y$},
    xmin=-1,
    xmax=11,
    ymin=-1,
    ymax=11,
    xtick={0,5,10},
    ytick={0,5,10},
    xticklabels={0,5,10},
    yticklabels={0,5,10},
    grid=both,
    major grid style={line width=0.2pt,draw=gray!50},
    minor grid style={line width=0.1pt,draw=gray!20},
    width=8cm,
    height=8cm,
    legend style={at={(0.5,1.02)},anchor=south},
    legend cell align=left,
    legend entries={Achse nach oben, Achse nach unten links, Achse nach unten rechts},
  ]
  
  % Achse nach oben
  \draw[thick,blue,-stealth] (axis cs:5,5) -- (axis cs:5,10.5);
  
  % Achse nach unten links
  \draw[thick,red,-stealth] (axis cs:5,5) -- (axis cs:0,0);
  
  % Achse nach unten rechts
  \draw[thick,green,-stealth] (axis cs:5,5) -- (axis cs:10,0);

\end{axis}
\end{tikzpicture}

\end{document}

答案1

改编

  • 注释掉导致错误的选项legend entries,因为您没有添加任何图\addplot

代码

\documentclass[a4paper,12pt]{article}

\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary {shapes.geometric, arrows}
\usepackage[margin=0.25in]{geometry}
\usepackage{pgfplots}
\pgfplotsset{width=10cm,compat=1.9}

\begin{document}

\begin{tikzpicture}
    \begin{axis}[
        axis equal,
        axis lines=middle,
        xlabel={$x$},
        ylabel={$y$},
        xmin=-1,
        xmax=11,
        ymin=-1,
        ymax=11,
        xtick={0,5,10},
        ytick={0,5,10},
        xticklabels={0,5,10},
        yticklabels={0,5,10},
        grid=both,
        major grid style={line width=0.2pt,draw=gray!50},
        minor grid style={line width=0.1pt,draw=gray!20},
        width=8cm,
        height=8cm,
        legend style={at={(0.5,1.02)},anchor=south},
        legend cell align=left,
        %legend entries={Achse nach oben, Achse nach unten links, Achse nach unten rechts}, % <---
    ]
    
        % Achse nach oben
        \draw[thick,blue,-stealth] (axis cs:5,5) -- (axis cs:5,10.5);
        
        % Achse nach unten links
        \draw[thick,red,-stealth] (axis cs:5,5) -- (axis cs:0,0);
        
        % Achse nach unten rechts
        \draw[thick,green,-stealth] (axis cs:5,5) -- (axis cs:10,0);
    \end{axis}
\end{tikzpicture}

\end{document}

相关内容