![直方图不起作用](https://linux22.com/image/404648/%E7%9B%B4%E6%96%B9%E5%9B%BE%E4%B8%8D%E8%B5%B7%E4%BD%9C%E7%94%A8.png)
我正在尝试编译它,但是它不起作用。你能帮我修复它吗?
\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}