此条形图仅显示第三个标签。如果我只放置一行数据,则标签会正常显示。如果我放置两行数据,则两个标签都会隐藏。如果我放置三行数据(如下所示),则仅显示第三个标签。
你知道为什么会发生这种情况吗?
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\pgfplotstableread{
X question interactionhigh InteractionLow VisualHigh VisualLow
1 {*I needed to learn a lot of material before I could get started with SIDNIE.} 6.50 6.18 6.22 5.96
2 {I felt very confident working with SIDNIE.} 5.60 5.55 6.11 6.04
3 {*I found the system very cumbersome for use.} 6.50 6.64 6.44 5.62
}\datatable
\begin{axis}[xbar=0,
yticklabels from table={\datatable}{question},
y tick label style={text width=5cm, align=right},
height=18cm,
width=10cm,
inner sep=0mm,
xmin=0,
xmax=7,
]
\addplot table[y=X,x={interactionhigh}] {\datatable};
\addplot table[y=X,x={InteractionLow}] {\datatable};
\addplot table[y=X,x={VisualHigh}] {\datatable};
\addplot table[y=X,x={VisualLow}] {\datatable};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
您需要明确指定要使用的刻度(通过说ytick={1,...,3}
),或者指定仅用数据标记坐标,通过说ytick=data
:
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\pgfplotstableread{
X question interactionhigh InteractionLow VisualHigh VisualLow
1 {*I needed to learn a lot of material before I could get started with SIDNIE.} 6.50 6.18 6.22 5.96
2 {I felt very confident working with SIDNIE.} 5.60 5.55 6.11 6.04
3 {*I found the system very cumbersome for use.} 6.50 6.64 6.44 5.62
}\datatable
\begin{axis}[xbar=0,
yticklabels from table={\datatable}{question},
y tick label style={text width=5cm, align=right},
y=2cm, enlarge y limits={abs=0.5},
width=10cm,
xmin=0,
xmax=7,
ytick=data,
]
\addplot table[y=X,x={interactionhigh}] {\datatable};
\addplot table[y=X,x={InteractionLow}] {\datatable};
\addplot table[y=X,x={VisualHigh}] {\datatable};
\addplot table[y=X,x={VisualLow}] {\datatable};
\end{axis}
\end{tikzpicture}
\end{document}