x 軸值彼此非常接近

x 軸值彼此非常接近

對於下面的 MWE:

\documentclass{report}
\usepackage[left=2.5cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage[T1]{fontenc}
\usepackage{pgfplots}


\begin{document}

\begin{figure}[H]
\centering
\begin{tikzpicture}
\begin{axis}[
ybar,
scaled y ticks = true,
ymajorgrids,
yminorgrids,
minor y tick num=5,
ylabel={Time Elapsed (in hours)},
xlabel={Methods},
width=1*\textwidth,
height=9cm,
bar width=4pt,
symbolic x coords={3,4,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35
},
xtick=data,
ymin=0
%nodes near coords,
%nodes near coords align={vertical},
]
        \addplot [fill=red]
        coordinates {(3,38.9575) (4,166.897) (6,53.63835) (7,39.6594) (8,82.1631) (9,40.22045) (10,37.2932) (11,131.62625) (12,472.6995) (13,149.837) (14,113.445) (15,108.474) (16,155.24455) (17,95.41392) (18,186.819) (19,153.383) (20,313.361) (21,180.1305) (22,401.3485) (23,1621.092) (24,1929.3) (25,899.283) (26,726.926) (27,1624.4) (28,870.348) (29,979.472) (30,869.418) (31,274.83) (32,1945.87) (33,1359.09) (34,891.24) (35,1625.31)     };
    \end{axis}
\end{tikzpicture}
\caption{}
\end{figure}

\end{document}

這個看起來不錯,但是當我將這個長條圖放入真實文件中時,x 軸值彼此更接近(例如 22,23 幾乎彼此接觸)。我不確定為什麼它只發生在那裡。也許這是序言?有任何想法嗎 ?

編輯:在實際文件中,它看起來像這樣,儘管差異很小,但每個條形都更接近(至少我是這樣看到的:)

在此輸入影像描述

答案1

我使用enlarge x limits=0.015tick label style={font=\footnotesize}來減小標籤使用的字體大小並控制 x 軸放大:

\documentclass{report}
\usepackage[left=2.5cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage[T1]{fontenc}
\usepackage{pgfplots}

\begin{document}

\begin{figure}[H]
\centering
\begin{tikzpicture}
\begin{axis}[
ybar,
scaled y ticks = true,
ymajorgrids,
yminorgrids,
minor y tick num=5,
ylabel={Time Elapsed (in hours)},
xlabel={Methods},
width=1*\textwidth,
height=9cm,
bar width=4pt,
symbolic x coords={3,4,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35
},
xtick=data,
ymin=0,
enlarge x limits=0.015,
tick label style={font=\footnotesize}
%nodes near coords,
%nodes near coords align={vertical},
]
        \addplot [fill=red]
        coordinates {(3,38.9575) (4,166.897) (6,53.63835) (7,39.6594) (8,82.1631) (9,40.22045) (10,37.2932) (11,131.62625) (12,472.6995) (13,149.837) (14,113.445) (15,108.474) (16,155.24455) (17,95.41392) (18,186.819) (19,153.383) (20,313.361) (21,180.1305) (22,401.3485) (23,1621.092) (24,1929.3) (25,899.283) (26,726.926) (27,1624.4) (28,870.348) (29,979.472) (30,869.418) (31,274.83) (32,1945.87) (33,1359.09) (34,891.24) (35,1625.31)     };
    \end{axis}
\end{tikzpicture}
\caption{}
\end{figure}

\end{document}

在此輸入影像描述

相關內容