tikzpicture 中的图形标签问题

tikzpicture 中的图形标签问题

下面的代码会产生很多错误,而同样的代码,如果只用 $\pi_1$ 而不是 $(s,\pi_1(s_0))$ 进行编译,则不会出现问题。有人能帮我想办法让更长的标签起作用吗?

    \begin{figure}
    \begin{tikzpicture}[scale=1,every node/.style={scale=0.8}],
    \centering
    \begin{axis}[
    height=7cm,
    width=13cm,  
      ymax=5,
      ymin=0,
      xmin=0.5,
      xmax=10.5,
      axis y line*=left,
      axis x line*=bottom,
      xticklabels={$(s,\pi_1(s_0))$,$x_2$,$x_2$,$x_3$, $x_4$,$x_5$,$x_6$,$x_7$,$x_8$, $x_9$},xtick={1,...,10},
      x tick label style={anchor=north}]
    \addplot+[only marks][error bars/.cd,y dir=both, y explicit]
    coordinates {
    (10,0.23333) +- (0.58257,-0.2159)
    (9,3.4) +- (2.04003,0.15997)
    (8,3.6) +- (1.82293,0.47707)
    (7,3.7667) +- (2.0352,0.3981)
    (6,0.44667) +- (0.94558,-0.41225)
    (5,2.5) +- (0.59648,-0.39648)
    (4,0.9) +- (1.67431,0.3569)
    (3,1.167) +- (0.09502,0.42835)
    (2,0.56667) +- (1.30495,-0.27162)
    (1,0.4) +- (1.06941,-0.16941)
    };
    
    \addplot[dashed] coordinates {(0,0) (10.5,0)};
    \end{axis}

答案1

这个小小的修改(我不知道您使用的包,但隐藏逗号在所有标准组合中应该是常见的)给出了图片。

\documentclass{article}

\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}

 \begin{figure}
    \begin{tikzpicture}[scale=1,every node/.style={scale=0.8}],
    \centering
    \begin{axis}[
    height=7cm,
    width=13cm,  
      ymax=5,
      ymin=0,
      xmin=0.5,
      xmax=10.5,
      axis y line*=left,
      axis x line*=bottom,
      xticklabels={${(s,\pi_1(s_0))}$,
      %$(s,\pi_1(s_0))$,
      $x_2$,$x_2$,$x_3$, $x_4$,$x_5$,$x_6$,$x_7$,$x_8$, $x_9$},xtick={1,...,10},
      x tick label style={anchor=north}]
    \addplot+[only marks][error bars/.cd,y dir=both, y explicit]
    coordinates {
    (10,0.23333) +- (0.58257,-0.2159)
    (9,3.4) +- (2.04003,0.15997)
    (8,3.6) +- (1.82293,0.47707)
    (7,3.7667) +- (2.0352,0.3981)
    (6,0.44667) +- (0.94558,-0.41225)
    (5,2.5) +- (0.59648,-0.39648)
    (4,0.9) +- (1.67431,0.3569)
    (3,1.167) +- (0.09502,0.42835)
    (2,0.56667) +- (1.30495,-0.27162)
    (1,0.4) +- (1.06941,-0.16941)
    };
    
    \addplot[dashed] coordinates {(0,0) (10.5,0)};
    \end{axis}
    
    \end{tikzpicture}
    \end{figure}
  
  \end{document}

在此处输入图片描述

相关内容