我正在尝试制作一个美观的数据直方图,到目前为止已经成功生成了以下内容:
\begin{tikzpicture}
\centering
\begin{axis}[
ymin=0, ymax=8000,
minor y tick num = 2,
axis background/.style={fill=gray!5},
area style,
]
\addplot+ [ybar interval,mark=no, fill={rgb:red,0;green,47;blue,135},draw=gray!5] plot coordinates { (0, 32) (5, 1228) (10, 6658) (15, 5060) (20, 1786) (25, 684) (30, 404) (35, 228) (40, 165) (45, 119) (50, 72)};
\end{axis}
\end{tikzpicture}
我想要让 x 标签显示为:0.0x、5.0x、10.0x 等。我该怎么做呢?
答案1
像这样,或者您想将数字除以 2?
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\centering
\begin{axis}[
ymin=0, ymax=8000,
minor y tick num = 2,
axis background/.style={fill=gray!5},
area style,
xticklabel=\pgfkeys{/pgf/number format/.cd,fixed,precision=1,zerofill}\pgfmathprintnumber{\tick}x,
]
\addplot+ [ybar interval,mark=no, fill={rgb:red,0;green,47;blue,135},draw=gray!5] plot coordinates { (0, 32) (5, 1228) (10, 6658) (15, 5060) (20, 1786) (25, 684) (30, 404) (35, 228) (40, 165) (45, 119) (50, 72)};
\end{axis}
\end{tikzpicture}
\end{document}