我们如何解决 x 轴的问题?另外,是否可以在每列的上方或中间写上每个数字?
为了制作条形图,我使用了以下代码:
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width = 0.85*\textwidth,
height = 8cm,
major x tick style = transparent,
ybar=2*\pgflinewidth,
bar width=14pt,
ymajorgrids = true,
ylabel = {Deaths per 1,000 live births},
symbolic x coords={World,Low income,Middle income, High income},
xtick = data,
scaled y ticks = false,
enlarge x limits=0.25,
ymin=0,
legend cell align=left,
legend style={
at={(1,1.05)},
anchor=south east,
column sep=1ex
}
]
\addplot
coordinates
{(World,51) (Low income,95) (Middle income,46) (High income,6)};
\addplot
coordinates
{(World,63) (Low income,115) (Middle income,57) (High income,7)};
\addplot
coordinates
{(World,73) (Low income,133) (Middle income,67) (High income,7)};
\addplot
coordinates
{(World,87) (Low income,164) (Middle income,82) (High income,12)};
\legend
{2011,2005,2000, 1990}
\end{axis}
\end{tikzpicture}
\end{document}
答案1
我使用选项{axis}[nodes near coords, x tick label style={rotate=45,anchor=east},]
,也许你可以尝试一下。
nodes near coords
为每个条形添加值。x tick label style={rotate=45,anchor=east},
以 45 度角旋转标签。
对于栏太宽,我认为bar width=12pt
已经足够了。