我一直试图让最后一个 x 刻度标签出现,但没有成功。
如您所见,除了那个微小的细节外,此图上的一切看起来都很整齐。我的强迫症不允许它保持这种状态,这就是我来寻求帮助的原因。我如何让“1600”出现?
这是我用来生成该代码的代码。
\documentclass{article}
\usepackage{pgfplotstable}
\usepackage{tikz}
\pgfplotsset{width=7.5cm,compat=1.12}
\usepgfplotslibrary{fillbetween}
\title{Title of Document}
\author{Name of Author}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
title={Score Distribution of the 1984 SAT},
ybar interval,
scaled y ticks = false,
xlabel={SAT Scores},
ylabel={Frequency},
xmin=200, xmax=1600,
ymin=0, ymax=18000,
xtick={200,400,600,800,1000,1200,1400,1600},
ytick={0,3000,6000,9000,12000,15000,18000},
x tick label style={rotate=45, anchor=east, align=left},
y tick label style={/pgf/number format/fixed},
xmajorgrids=false,
ymajorgrids=true,
grid style=dashed,
enlarge x limits=0.03,
]
\addplot coordinates {(1600,5) (1580,27) (1570,19) (1560,39) (1550,75) (1540,96) (1530,108) (1520,188) (1510,217) (1500,278) (1490,316) (1480,404) (1470,473) (1460,617) (1450,601) (1440,795) (1430,874) (1420,1071) (1410,1196) (1400,1323) (1390,1439) (1380,1621) (1370,1871) (1360,2028) (1350,2267) (1340,2495) (1330,2698) (1320,3155) (1310,3334) (1300,3661) (1290,3730) (1280,4099) (1270,4393) (1260,4762) (1250,4923) (1240,5623) (1230,5701) (1220,6143) (1210,6797) (1200,6878) (1190,7091) (1180,7500) (1170,7981) (1160,8346) (1150,8790) (1140,9470) (1130,9715) (1120,10293) (1110,10639) (1100,11136) (1090,11288) (1080,11713) (1070,12224) (1060,12652) (1050,13057) (1040,13733) (1030,14064) (1020,14333) (1010,15109) (1000,15082) (990,15118) (980,15440) (970,15566) (960,16294) (950,16368) (940,16640) (930,16899) (920,16539) (910,17351) (900,17089) (890,17138) (880,16936) (870,17233) (860,17155) (850,17439) (840,16933) (830,16801) (820,16903) (810,16639) (800,16061) (790,15862) (780,15540) (770,15881) (760,14992) (750,14778) (740,14413) (730,14061) (720,13761) (710,13365) (700,12795) (690,12094) (680,11942) (670,11579) (660,10532) (650,10727) (640,9990) (630,9674) (620,9512) (610,8621) (600,8412) (590,7958) (580,7304) (570,7139) (560,6412) (550,5974) (540,5654) (530,5086) (520,4796) (510,4216) (500,3769) (490,3275) (480,2812) (470,2439) (460,1785) (450,1737) (440,1107) (430,665) (420,431) (410,326) (400,204) (380,1) (370,3) (360,1) (350,3) (340,1) (330,1) (320,2) (310,2) (270,3) (260,3) (240,1)};
\end{axis}
\end{tikzpicture}
\end{document}
提前致谢。
答案1
- 我不是专家,但我认为我找到了解释。
- 当我将其旋转
x tick labels
90 度而不是 45 度时,可能发生的情况就更加明显了:标签位于间隔的中心。 - 因此我在 1800 处添加了另一个刻度,以便显示 1600 刻度。
\documentclass{article}
\usepackage{pgfplotstable}
\usepackage{tikz}
\pgfplotsset{width=7.5cm,compat=1.12}
\usepgfplotslibrary{fillbetween}
\title{Title of Document}
\author{Name of Author}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
title={Score Distribution of the 1984 SAT},
ybar interval,
scaled y ticks = false,
xlabel={SAT Scores},
ylabel={Frequency},
xmin=200,
xmax=1800, % Modified
ymin=0,
ymax=18000,
xtick={200,400,600,800,1000,1200,1400,1600,1800}, % Modified
ytick={0,3000,6000,9000,12000,15000,18000},
x tick label style={rotate=90, anchor=east, align=left},
y tick label style={/pgf/number format/fixed},
xmajorgrids=false,
ymajorgrids=true,
grid style=dashed,
enlarge x limits=0.03,
]
\addplot coordinates {(1600,5) (1580,27) (1570,19) (1560,39) (1550,75) (1540,96) (1530,108) (1520,188) (1510,217) (1500,278) (1490,316) (1480,404) (1470,473) (1460,617) (1450,601) (1440,795) (1430,874) (1420,1071) (1410,1196) (1400,1323) (1390,1439) (1380,1621) (1370,1871) (1360,2028) (1350,2267) (1340,2495) (1330,2698) (1320,3155) (1310,3334) (1300,3661) (1290,3730) (1280,4099) (1270,4393) (1260,4762) (1250,4923) (1240,5623) (1230,5701) (1220,6143) (1210,6797) (1200,6878) (1190,7091) (1180,7500) (1170,7981) (1160,8346) (1150,8790) (1140,9470) (1130,9715) (1120,10293) (1110,10639) (1100,11136) (1090,11288) (1080,11713) (1070,12224) (1060,12652) (1050,13057) (1040,13733) (1030,14064) (1020,14333) (1010,15109) (1000,15082) (990,15118) (980,15440) (970,15566) (960,16294) (950,16368) (940,16640) (930,16899) (920,16539) (910,17351) (900,17089) (890,17138) (880,16936) (870,17233) (860,17155) (850,17439) (840,16933) (830,16801) (820,16903) (810,16639) (800,16061) (790,15862) (780,15540) (770,15881) (760,14992) (750,14778) (740,14413) (730,14061) (720,13761) (710,13365) (700,12795) (690,12094) (680,11942) (670,11579) (660,10532) (650,10727) (640,9990) (630,9674) (620,9512) (610,8621) (600,8412) (590,7958) (580,7304) (570,7139) (560,6412) (550,5974) (540,5654) (530,5086) (520,4796) (510,4216) (500,3769) (490,3275) (480,2812) (470,2439) (460,1785) (450,1737) (440,1107) (430,665) (420,431) (410,326) (400,204) (380,1) (370,3) (360,1) (350,3) (340,1) (330,1) (320,2) (310,2) (270,3) (260,3) (240,1)};
\end{axis}
\end{tikzpicture}
\end{document}