我刚开始使用 pgfplots,在格式化条形图方面有一个小问题。具体来说,我试图为每个 y 轴添加标签,但我搞不懂。
\begin{tikzpicture}
\begin{axis}[
title={How Well Do You Relate to Your Online Persona?
every axis plot post/.style={/pgf/number format/fixed},
ybar=5pt,
bar width=80pt,
x=3cm,
ymin=0,
axis on top,
ymax=6,
xtick=data,
enlarge x limits=0.2,
symbolic x coords={Person1,Person2},
]
\addplot coordinates {(Person1,5) (Person2,2)};
\end{axis}
\end{tikzpicture}
答案1
要以自定义间隔将刻度放置在 y 轴上,您只需使用指令ytick = {<ticks>}
,如手册第 4.14.1 节所述pgfplots
。
我还改编了 Jubobs 的评论,为 yticks 放置“说话”标签。
这是一个 MWE,说明了这一点
\documentclass[border=3mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
title={How Well Do You Relate to Your Online Persona?},
every axis plot post/.style={/pgf/number format/fixed},
ybar=5pt,
bar width=80pt,
x=3cm,
ymin=0,
axis on top,
ymax=6,
xtick=data,
ytick={0,...,6},
yticklabels={Not at all, a bit, so so, quite well, well enough, very well},
enlarge x limits=0.2,
symbolic x coords={Person1,Person2},
]
\addplot coordinates {(Person1,5) (Person2,2)};
\end{axis}
\end{tikzpicture}
\end{document}