我正在使用 pgfplots 和 tikz 创建直方图。我曾使用 tikz 绘制其他图形,但从未绘制过图表。
我正在运行的代码是:
\documentclass[oneside,12pt,openany,fleqn]{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[
ymin=0, ymax=12,
minor y tick num = 3,
area style,
]
\addplot+[ybar interval,mark=no] plot coordinates { (0, 1) (5, 0) (10, 0) (15, 0) (20, 0) (25, 0) (30, 1) (35, 2) (40, 2) (45, 5) (50, 7) (55, 6) (60, 10) (65, 10) (70, 6) (75, 9) (80, 2) (85, 1) (90, 3) (95, 1) };
\end{axis}
\end{tikzpicture}
\caption[A1 Average of Classcraft Participants]{A1 Average of Classcraft Participants}
\label{fig:players-A1-average}
\end{figure}
\end{document}
我对它的外观非常满意,我想要的只是调整 x 轴的比例,以便显示我为 x 坐标给出的所有数值。
有人可以帮忙吗?
答案1
xtick distance=5
由于x 轴上有如此多的数字( ),您还需要更宽的图表来为它们腾出空间,例如这样:
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width=\textwidth,
height=7cm,
xmin=0, xmax=100,
ymin=0, ymax=12,
xtick distance=5,
minor y tick num = 3,
area style,
]
\addplot+[ybar interval] plot coordinates { (0, 1) (5, 0) (10, 0) (15, 0) (20, 0) (25, 0) (30, 1) (35, 2) (40, 2) (45, 5) (50, 7) (55, 6) (60, 10) (65, 10) (70, 6) (75, 9) (80, 2) (85, 1) (90, 3) (95, 1) };
\end{axis}
\end{tikzpicture}
\end{document}