![如何使用 pgfplots 创建带有间隔和符号的直方图?](https://linux22.com/image/436824/%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8%20pgfplots%20%E5%88%9B%E5%BB%BA%E5%B8%A6%E6%9C%89%E9%97%B4%E9%9A%94%E5%92%8C%E7%AC%A6%E5%8F%B7%E7%9A%84%E7%9B%B4%E6%96%B9%E5%9B%BE%EF%BC%9F.png)
pgfplots
我正在尝试使用 TeX 重新创建我最初使用 Excel 创建的 直方图:
我遇到的问题是我不知道如何使用 重新创建x-axis
。pgfplots
到目前为止,我已实现以下目标:
具有当前直方图的最小工作示例:
\documentclass[12pt, DIV=12, paper=A4]{scrreprt}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\usepgfplotslibrary{statistics}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ybar,
ymajorgrids,
axis lines* = left,
width = \linewidth,
ytick style = {draw=none},
enlargelimits = 0.15,
xtick = {750, 760, 770, 780, 790, 800, 810, 820, 830, 840, 850, 860, 870, 880, 890, 900, 910, 920, 930, 940, 950, 960, 970, 980, 990, 1000},
symbolic x coords = {750, 760, 770, 780, 790, 800, 810, 820, 830, 840, 850, 860, 870, 880, 890, 900, 910, 920, 930, 940, 950, 960, 970, 980, 990, 1000},
x tick label style = {rotate=90,anchor=east},
legend style = {at={(0.5,1.03)}, anchor=south, legend columns = -1},
]
\addplot[red!20!black,fill=red!80!white] coordinates {(750,114) (760,252) (770,326) (780,363) (790,341) (800,306) (810,497) (820,2728) (830,1750) (840,372) (850,277) (860,210) (870,294) (880,191) (890,208) (900,129) (910,143) (920,98) (930,89) (940,103) (950,105) (960, 54) (970, 35) (980,24) (990,20) (1000,75)};
\end{axis}
\end{tikzpicture}
\end{document}
文档展示了如何使用以下命令创建间隔:
xticklabel={
$[\pgfmathprintnumber\tick,
\pgfmathprintnumber\nexttick)$
},
但我不确定如何将小于等于和大于符号添加到这些间隔中。
我非常感谢你的帮助!
答案1
如果你真的非常想要,那么你可以使用 PGFPlots 来模仿 Excel。Excel 是一个非常好的电子表格,但会产生非常差/错误的视觉输出。
\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ybar, bar width=9,
ymajorgrids,
axis lines*= left,
width=\linewidth,
xtick style= {draw=none}, ytick style= {draw=none},
enlargelimits=0.15,
xtick={750, 760, 770, 780, 790, 800, 810, 820, 830, 840, 850, 860, 870, 880, 890, 900, 910, 920, 930, 940, 950, 960, 970, 980, 990,1000},
x tick label style = {rotate=90, yshift=1ex, font=\tiny},
x tick label as interval=true,
xticklabel={$(\pgfmathprintnumber{\tick}, \pgfmathprintnumber{\nexttick}]$},
extra x ticks={1000,1010},
extra x tick label={> \pgfmathprintnumber{\tick}},
x tick label style = {/pgf/number format/set thousands separator={.}},
y tick label style = {/pgf/number format/set thousands separator={\,}},
]
\addplot[draw=blue!50, fill=blue!50] coordinates {(750,114) (760,252) (770,326) (780,363) (790,341) (800,306) (810,497) (820,2728) (830,1750) (840,372) (850,277) (860,210) (870,294) (880,191) (890,208) (900,129) (910,143) (920,98) (930,89) (940,103) (950,105) (960, 54) (970, 35) (980,24) (990,20) (1000,75)};
\end{axis}
\end{tikzpicture}
\end{document}