我终于设法用 将数据置于中心axis x line*=center
,但我还没有找到将数据置于图底部的方法x tick labels
。我已经绘制了一些主要网格线,现在我想将刻度标签置于图底部。
我曾尝试使用at={()}
,但似乎不起作用。
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\pgfplotstableread{data/multicontrol.dat}\datatable
\begin{axis}[ybar=0,
bar width={0.2cm},
xticklabels from table={\datatable}{variable},
xtick=data,
x tick label style={
rotate=60,anchor=east},
yticklabels={X,Very Bad, Bad, Neutral, Good, Very Good},
xmajorgrids,
ymin=-2,
ymax=2,
axis x line*=middle,
axis y line*=left,
enlarge x limits,
y filter/.code={\pgfmathparse{#1-3}}
]
\addplot table[x=X,y=old] {\datatable};
\addlegendentry{Joystick}
\addplot table[x=X,y=new] {\datatable};
\addlegendentry{Mouse}
\end{axis}
\end{tikzpicture}
\end{document}
示例数据:
X variable old new
1 {Know where I am} 2.375 4
2 {Know what I see} 3.375 4.375
3 {See target directly} 2.428571429 4.5
4 {Know origin} 3.875 4.285714286
5 {Direct Adjustment (inv)} 2.625 3.75
6 {Screen position} 3.25 4.125
7 {Expectation} 2.25 2.375
8 {Get lost (inv)} 2.714285714 3.5
9 {Number dependent (inv)} 2 4
答案1
这里最简单的做法是使用axis x line*=left
(而不是中间),将轴线和标签放置在图的底部,并使用以下方法之一“伪造”零线如何在绘图中添加零线?。
对于此图,我建议翻转轴吗?这样可以更轻松地读取标签,因为您无需旋转即可完成:
第一个解决方案的代码
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\pgfplotstableread{
X variable old new
1 {Know where I am} 2.375 4
2 {Know what I see} 3.375 4.375
3 {See target directly} 2.428571429 4.5
4 {Know origin} 3.875 4.285714286
5 {Direct Adjustment (inv)} 2.625 3.75
6 {Screen position} 3.25 4.125
7 {Expectation} 2.25 2.375
8 {Get lost (inv)} 2.714285714 3.5
9 {Number dependent (inv)} 2 4
}\datatable
\begin{axis}[ybar=0,
bar width={0.2cm},
xticklabels from table={\datatable}{variable},
xtick=data,
x tick label style={
rotate=60,anchor=east},
yticklabels={X,Very Bad, Bad, Neutral, Good, Very Good},
xmajorgrids,
ymin=-2,
ymax=2,
axis x line*=left,
axis y line*=left,
enlarge x limits,
y filter/.code={\pgfmathparse{#1-3}},
after end axis/.code={\draw ({rel axis cs:0,0}|-{axis cs:0,0}) -- ({rel axis cs:1,0}|-{axis cs:0,0});}
]
\addplot table[x=X,y=old] {\datatable};
\addlegendentry{Joystick}
\addplot table[x=X,y=new] {\datatable};
\addlegendentry{Mouse}
\end{axis}
\end{tikzpicture}
\end{document}
第二种解决方案的代码
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\pgfplotstableread{
X variable old new
1 {Know where I am} 2.375 4
2 {Know what I see} 3.375 4.375
3 {See target directly} 2.428571429 4.5
4 {Know origin} 3.875 4.285714286
5 {Direct Adjustment (inv)} 2.625 3.75
6 {Screen position} 3.25 4.125
7 {Expectation} 2.25 2.375
8 {Get lost (inv)} 2.714285714 3.5
9 {Number dependent (inv)} 2 4
}\datatable
\begin{axis}[xbar=0,
bar width={0.2cm},
yticklabels from table={\datatable}{variable},
ytick=data,
xticklabels={X,Very Bad, Bad, Neutral, Good, Very Good},
xmajorgrids,
xmin=-2,
xmax=2,
axis x line*=left,
axis y line*=left,
enlarge x limits,
x filter/.code={\pgfmathparse{#1-3}},
after end axis/.code={\draw ({rel axis cs:0,0}-|{axis cs:0,0}) -- ({rel axis cs:0,1}-|{axis cs:0,0});},
legend style={at={(1,0.9)}}
]
\addplot table[y=X,x=old] {\datatable};
\addlegendentry{Joystick}
\addplot table[y=X,x=new] {\datatable};
\addlegendentry{Mouse}
\end{axis}
\end{tikzpicture}
\end{document}