我有一组数字作为 x 坐标:{2.08, 2.09, 2.7, 4.9, 12.8, 29.3, 64.2}
。图的左侧部分太紧,因为2.08
和2.09
非常接近。我想均匀地将数字集分布在 x 轴上。可能吗?怎么做?请参见以下示例:
\begin{figure}[!h]
\centering
\caption{The example.}
\label{figure:the_example}
\begin{tikzpicture}[scale=0.45]
\begin{axis}[ybar,xtick=data,xlabel=$ \lambda $,ylabel=$ \alpha $,
x tick label style={rotate=-35,anchor=west},width=2.2\textwidth,
height=0.32\textheight,legend pos=north west,ymin=0]
\addplot coordinates {
(2.08,10)
(2.09,15)
(2.7,25)
(4.9,22)
(12.8,21)
(29.3,12)
(64.2,17)
};
\end{axis}
\end{tikzpicture}
\end{figure}
答案1
您可以使用symbolic x coords
:
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.7}
\begin{document}
\begin{tikzpicture}[scale=0.45]
\begin{axis}[
ybar,
xlabel=$\lambda$,ylabel=$\alpha$,
symbolic x coords={2.08,2.09,2.7,4.9,12.8,29.3,64.2},
]
\addplot coordinates {
(2.08,10)
(2.09,15)
(2.7,25)
(4.9,22)
(12.8,21)
(29.3,12)
(64.2,17)
};
\end{axis}
\end{tikzpicture}
\end{document}