直方图不起作用

直方图不起作用

我正在尝试编译它,但是它不起作用。你能帮我修复它吗?

\documentclass{standalone}

\usepackage{tikz}
\usepackage{subcaption}
\begin{document}
        
        \pgfplotsset{x=\linewidth/7,
            width=0.8\textwidth,height=0.9\textwidth,
            axis line style = ,
            ybar, 
            xlabel={Calificaci\'on},
            ylabel={Porcentaje ($\%$)},
            label style={font=\tiny},
            ymin=0,
            ytick=\empty,
            xtick=data,
            enlarge x limits=0.2,
            xticklabel style={anchor=base,yshift=-\baselineskip},
            nodes near coords={\pgfmathprintnumber\pgfplotspointmeta\%},
            nodes near coords style={font=\scriptsize},
            xtick align=inside
        }
        
        \begin{subfigure}{0.45\linewidth}
            \begin{tikzpicture}
            \begin{axis}[bar width=22pt]
            \addplot[black,fill=blue] coordinates {
                (1, 6.110)
                (2, 11.370)
                (3, 27.145)
                (4, 34.174)
                (5, 21.201)
            };
            \end{axis}
            \end{tikzpicture}

        \end{subfigure}
        \begin{subfigure}{0.45\textwidth}
            \begin{tikzpicture}
            \begin{axis}[bar width=22pt]
            \addplot[black,fill= blue] coordinates {
                (1, 5.616226)
                (2, 10.753453)
                (3, 27.145)
                (4, 34.889808)
                (5, 22.626271)
            };
            \end{axis}
            \end{tikzpicture}

        \end{subfigure}
        
\end{document}

错误:

错误日志的屏幕截图

答案1

figure在内部不起作用standalone,您需要包装subfigure内部figure环境(如前所述@Ieandriis)。并且您需要使用pgfplots包;)

干得好:

\documentclass{article}

\usepackage{tikz}
\usepackage{subcaption}
\usepackage{pgfplots}
\begin{document}
\begin{figure*}
{
    \pgfplotsset{x=\linewidth/7,
    width=0.8\textwidth,height=0.9\textwidth,
    axis line style = ,
    ybar, 
    xlabel={Calificaci\'on},
    ylabel={Porcentaje ($\%$)},
    label style={font=\tiny},
    ymin=0,
    ytick=\empty,
    xtick=data,
    enlarge x limits=0.2,
    xticklabel style={anchor=base,yshift=-\baselineskip},
    nodes near coords={\pgfmathprintnumber\pgfplotspointmeta\%},
    nodes near coords style={font=\scriptsize},
    xtick align=inside,
}
  \begin{subfigure}{0.45\linewidth}
    \begin{tikzpicture}
    \begin{axis}[bar width=22pt]
    \addplot[black,fill=blue] coordinates {
        (1, 6.110)
        (2, 11.370)
        (3, 27.145)
        (4, 34.174)
        (5, 21.201)
    };
    \end{axis}
    \end{tikzpicture}

\end{subfigure}
        \begin{subfigure}{0.45\textwidth}
    \begin{tikzpicture}
    \begin{axis}[bar width=22pt]
    \addplot[black,fill= blue] coordinates {
        (1, 5.616226)
        (2, 10.753453)
        (3, 27.145)
        (4, 34.889808)
        (5, 22.626271)
    };
    \end{axis}
    \end{tikzpicture}


\end{subfigure}
}


  \end{figure*}



\end{document}

在此处输入图片描述

相关内容