有没有什么办法可以让这个图中的条形图更加紧密?它们之间似乎有很多未使用的空间。
\begin{tikzpicture}[]
\begin{axis}[
xmin=0,xmax=80,height = 3in, width=10in, bar width=1mm,
% x=2.5mm, xbar=0.1pt, these don't seem to have an effect here
ytick = {0,1,...,4},yticklabels={clear,tint,red,dark,dark red},
xtick = {1,3,...,71}, xticklabels =
{24,25,26,27,28,29,30,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
16,17,18,19,20,21,22,23,24,25,26,27,28,29}]
\addplot+[ ybar,mark=0,fill=pink,draw=none] coordinates {
(
(1,3)(2,3)(3,1)(4,4)(5,3)(6,4)(7,3)(8,2)(9,3)
(10,2)(11,1)(12,3)(13,3)(14,2)(15,1)(16,2)(17,3)
(18,4)(19,3)(20,2)(21,4)(22,3)(23,1)(24,4)(25,1)
(26,4)(27,3)(28,4)(29,3)(30,3)(31,3)(32,4)(33,1)
(34,2)(35,0)(36,1)(37,1)(38,4)(39,1)(40,4)(41,3)
(42,4)(43,3)(44,4)(45,3)(46,3)(47,1)(48,1)(49,0)
(50,1)(51,0)(52,1)(53,3)(54,1)(55,1)(56,3)(57,1)
(58,4)(59,1)(60,1)(61,3)(62,2)(63,0)(64,1)(65,0)
(66,1)(67,0)(68,2)(69,1)(70,1)(71,2)
};
\end{axis}
\end{tikzpicture}
答案1
好吧,在 10 英寸宽的图中,条形的宽度为 1 毫米,因此它们只能占用这么多空间。减小轴的宽度和/或增加条形的宽度会占用更多空间。下面,我还减小了xmax
x 轴上刻度标签的字体大小,这样它们就不会那么靠近了。
\documentclass[border=3mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin=0,xmax=72,height = 3in, width=6in, bar width=1.5mm,
ytick = {0,1,...,4},yticklabels={clear,tint,red,dark,dark red},
xtick = {1,3,...,71}, xticklabels =
{24,25,26,27,28,29,30,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
16,17,18,19,20,21,22,23,24,25,26,27,28,29},
xticklabel style={font=\footnotesize}]
\addplot+[ ybar,mark=0,fill=pink,draw=none] coordinates {
(1,3)(2,3)(3,1)(4,4)(5,3)(6,4)(7,3)(8,2)(9,3)
(10,2)(11,1)(12,3)(13,3)(14,2)(15,1)(16,2)(17,3)
(18,4)(19,3)(20,2)(21,4)(22,3)(23,1)(24,4)(25,1)
(26,4)(27,3)(28,4)(29,3)(30,3)(31,3)(32,4)(33,1)
(34,2)(35,0)(36,1)(37,1)(38,4)(39,1)(40,4)(41,3)
(42,4)(43,3)(44,4)(45,3)(46,3)(47,1)(48,1)(49,0)
(50,1)(51,0)(52,1)(53,3)(54,1)(55,1)(56,3)(57,1)
(58,4)(59,1)(60,1)(61,3)(62,2)(63,0)(64,1)(65,0)
(66,1)(67,0)(68,2)(69,1)(70,1)(71,2)
};
\end{axis}
\end{tikzpicture}
\end{document}