带有 tikzpicture 的条形图

带有 tikzpicture 的条形图

我有这个条形图,但我看不到 x 轴上的所有标签。我遗漏了什么?此外,熵条不在正确的位置。

谢谢。

\begin{figure}[h!]
\begin{tikzpicture}
\small
\begin{axis} [ybar,
    bar width = 10pt,
    width = 1\textwidth,
    height = 0.5\textwidth,
    legend style={at={(0.25,+0.075)}, anchor=north,legend columns=-1},
    ylabel={Variable importance},
    xlabel={Bands},
    enlargelimits=0.09,
    symbolic x coords={B2, B3, B4, B5, B6, B8, B11, B12, NDBI, NDVI, VH, VV, Entropy, Alpha, ratio, sum,},
    xtick=data,  
]    

\addplot [fill = green, error bars/.cd,
          y dir=both, y explicit] coordinates{
(B2,1.303)+-(0, 0.069)
(B3,1.257)+-(0, 0.087)
(B4,1.222)+-(0, 0.099)
(B5,1.135)+-(0, 0.079)
(B6,1.134)+-(0, 0.077)
(B8,1.138)+-(0, 0.080)
(B11,1.127)+-(0,0.084)
(B12,1.187)+-(0,0.085)
(NDBI,1.252)+-(0,0.080)
(NDVI,1.291)+-(0,0.083)
};


\addplot [fill = red, error bars/.cd,
          y dir=both, y explicit] coordinates{
(VH,1.241)+-(0, 0.076)
(VV,1.134)+-(0, 0.080)
};

\addplot [fill = yellow, error bars/.cd,
          y dir=both, y explicit] coordinates{
(Entropy,1.121)+-(0,0.100)
(Alpha,1.116)+-(0,0.096 )
(ratio,1.156)+-(0,0.086 )
(span,1.147)+-( 0,0.081 )
};

%\legend {Optical, Radar, Radar $H/\alpha$};
 
\end{axis}
\label{accuracy}
\end{tikzpicture}
\caption{mean variable importance and standard deviation calculated in GEE.}
\label{importance}
\end{figure}

在此处输入图片描述

答案1

像这样?

编辑: 添加了轴标签和ymin选项ymax

在此处输入图片描述

  • 您仅提供代码片段...
  • 它有一些错误/混乱
  • 为了正确定位 x tick,至少\addplot必须使用 all xticks,这些命令稍后可以被其他\addplots 命令覆盖:
\documentclass{article} 
\usepackage{geometry} % layout

\usepackage{pgfplots} 
\pgfplotsset{compat=1.18}


\begin{document}
    \begin{figure}[h!]
    \begin{tikzpicture}
\begin{axis}[
    x=8mm,
    ybar=-5mm,
    bar width = 5mm,
    symbolic x coords={B2, B3, B4, B5, B6, B8, B11, B12, %
                       NDBI, NDVI, VH, VV, %
                       Entropy, Alpha, ratio, sum},
    xtick=data,
    x tick label style = {rotate=45, anchor=east, font=\footnotesize},
    enlarge x limits=0.05,
    ylabel={Variable importance},
    xlabel={Bands},
    ymin=1, ymax=1.5    
            ]
\addplot [fill = green, error bars/.cd,
          y dir=both, y explicit] coordinates{
    (B2,    1.303)+-(0, 0.069)
    (B3,    1.257)+-(0, 0.087)
    (B4,    1.222)+-(0, 0.099)
    (B5,    1.135)+-(0, 0.079)
    (B6,    1.134)+-(0, 0.077)
    (B8,    1.138)+-(0, 0.080)
    (B11,   1.127)+-(0, 0.084)
    (B12,   1.187)+-(0, 0.085)
    (NDBI,  1.252)+-(0, 0.080)
    (NDVI,  1.291)+-(0, 0.083)
%
    (VH,0) +-(0,0)
    (VV,0) +-(0,0)
%
    (Entropy,0) +-(0,0)
    (Alpha,06)  +-(0,0)
    (ratio,0)   +-(0,0)
    (sum,0)     +-(0,0)
    };

\addplot [fill = red, error bars/.cd,
          y dir=both, y explicit] coordinates{
    (VH,    1.241)+-(0, 0.076)
    (VV,    1.134)+-(0, 0.080)
    };

\addplot [fill = yellow, error bars/.cd,
          y dir=both, y explicit] coordinates{
    (Entropy,   1.121)+-(0, 0.100)
    (Alpha,     1.116)+-(0, 0.096)
    (ratio,     1.156)+-(0, 0.086)
    (sum,       1.147)+-(0, 0.081)
    };

\end{axis}
    \end{tikzpicture}
\caption{mean variable importance and standard deviation calculated in GEE.}
\label{importance}
    \end{figure}
\end{document}

相关内容