我想为所附图表的 x 轴添加自定义间隔。它应该从 20 开始,然后增加 5。例如,20、25、30、......50。之前有人问过类似的问题,但没有任何答案就关闭了。提前非常感谢。我的代码如下所示。
\begin{figure}[!h]
\begin{centering}
%\begin{adjustwidth}{-1.5cm}{}
\begin{tikzpicture}
\begin{axis}[
footnotesize,
xbar,
width=11.0cm, height=4.5cm,
enlarge y limits=0.01,
enlargelimits=0.07,
%xlabel={\#participants},
symbolic y coords={Al, Stor, Pro, Ser, Domain, Services},
ytick=data,
nodes near coords, nodes near coords align={horizontal},
every node near coord/.append style={font=\footnotesize},
]
\addplot coordinates {
(48,Services) (27,Domain) (26,Ser) (25,Pro) (23,Stor) (37,All)};
\end{axis}
\end{tikzpicture}
\caption{Design}
%\end{adjustwidth}
\label{fig:SQ21}
\end{centering}
\end{figure}
答案1
正如问题下方的评论中所述,只需在选项中添加xmin=20
和即可实现您想要的效果。xtick distance=5
axis
% used PGFPlots v1.17
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
footnotesize,
xbar,
width=11.0cm, height=4.5cm,
% ---------------------------------------------------------------------
% added
xmin=20,
xtick distance=5,
% ---------------------------------------------------------------------
enlarge y limits=0.01,
enlargelimits=0.07,
symbolic y coords={All, Stor, Pro, Ser, Domain, Services},
ytick=data,
nodes near coords,
nodes near coords align={horizontal},
every node near coord/.append style={font=\footnotesize},
]
\addplot coordinates {
(48,Services) (27,Domain) (26,Ser) (25,Pro) (23,Stor) (37,All)
};
\end{axis}
\end{tikzpicture}
\end{document}