我关注了在 TikZ/PGF 轴环境中隐藏刻度数。。但是,xticklabels=\empty
似乎没有覆盖指数部分。这是代码。
\documentclass[12pt]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\begin{document}
\begin{figure} \centering
\begin{tikzpicture}
\begin{axis}[
legend columns=-1,
legend style={at={(1,0)},anchor=south east},
width=.8\textwidth,
height=\textwidth,
bar width=8pt,
xmin=0,
xmax=17000,
xbar,
tickwidth = 0pt,
ytick = data,
xticklabels=\empty,
%enlargelimits=auto,
%enlarge y limits = 0.01,
enlarge x limits = 0.02,
symbolic y coords = {Animals, Vegetables, Food products, Minerals, Fuel, Chemicals, Plastic and rubber, Leather, Wood, Textiles},
nodes near coords
]
\addplot coordinates {(863.9,Animals) (3461.3,Vegetables) (913.8,Food products) (527.1,Minerals) (372.1,Fuel) (386.3,Chemicals) (392.7,Plastic and rubber) (860.5,Leather) (90,Wood) (13655.1,Textiles)};
\addplot coordinates {(17.8,Animals) (1457.8,Vegetables) (112.5,Food products) (71.9,Minerals) (2457.2,Fuel) (206.8,Chemicals) (402.2,Plastic and rubber) (51.1,Leather) (35.9,Wood) (1940.6,Texti
les)};
\legend{Exporters, Importers}
\end{axis}
\end{tikzpicture}
\caption{Export across industrial sectors} \label{f:sectors}
\end{figure}
\end{document}
答案1
不要使用 ,而是xticklabels=\empty
使用xtick=\empty
,这样可以删除所有刻度,而不仅仅是属于刻度的文本标签。比例因子也会消失。如果您不添加网格线,我建议您这样做。
如果您要添加网格线,那么您需要刻度,因此请使用scaled x ticks=false
删除比例因子。
请注意,使用 时xticklabels=\empty
,这些标签的节点仍然存在,但为空,因此它们占用空间,并有效地向图表中添加空白。例如,如果您有,xticklabels=\empty, scaled x ticks=false, xticklabel style={draw}
您可以看到节点在那里:
但是由于xtick=\empty
节点不存在,并且标题和轴框之间的空白较少: