我怎样才能删除两个垂直轴上的小破折号?标签和 xbar 之间不应该有任何破折号。
我的文件datatable.txt
:
one two three
A 2 0.3
B 3 0.4
C 4 0.5
D 5 0.6
E 4 0.7
F 3 0.6
G 2 0.5
H 3 0.4
I 4 0.3
J 5 0.4
K 4 0.5
L 3 0.6
M 2 0.7
N 3 0.6
我的代码:
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\begin{document}
\begin{figure}[h!]
\centering
\begin{tikzpicture}
\begin{axis}[
xbar,
xmin=1,
xmax=6,
ytick=data,
yticklabels from table={datatable.txt}{one}
]
\addplot plot [error bars/.cd, x dir = both, x explicit] table [x=two, y expr=\coordindex, x error = three] {datatable.txt};
\end{axis}
\end{tikzpicture}
\caption{xbars and standard deviations}
\end{figure}
\end{document}
答案1
而不是ytick style={draw=none}
像罗斯在他的回答您可以/应该使用major tick length=0pt
,这样yticks
距离也可以yticklabels
得到适当调整。
有关更多详细信息,请查看代码中的注释。
% used PGFPlots v1.15
\begin{filecontents*}{datatable.txt}
one two three
A 2 0.3
B 3 0.4
C 4 0.5
D 5 0.6
E 4 0.7
F 3 0.6
G 2 0.5
H 3 0.4
I 4 0.3
J 5 0.4
K 4 0.5
L 3 0.6
M 2 0.7
N 3 0.6
\end{filecontents*}
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xbar,
xmin=1,
xmax=6,
ytick=data,
yticklabels from table={datatable.txt}{one},
error bars/x dir=both,
error bars/x explicit,
y dir=reverse,
% % ---------------------------------------------------------------------
% % (just added to illustrate the problem when using Ross' solution
% % <https://tex.stackexchange.com/a/388117> or the following commented one)
% major tick length=50pt,
% % ---------------------------------------------------------------------
% % simply set the tick length for the y ticks to zero,
% % but then the distance to of the ticklabels isn't adjusted
% % (maybe this is a bug?)
% ytick style={
% /pgfplots/major tick length=0pt,
% },
% ---------------------------------------------------------------------
% to circumvent that problem, first set (all) tick length to zero
% and and then restore the default length for the xticks
% doing that the yticklabels have the "right" distance to the y-axis
% (compare with the distance of the xticklabels to the x-axis)
major tick length=0pt,
xtick style={
/pgfplots/major tick length=1.5mm,
},
% ---------------------------------------------------------------------
]
\addplot table [
x=two,
y expr=\coordindex,
x error=three,
] {datatable.txt};
\end{axis}
\end{tikzpicture}
\end{document}
答案2
添加ytick style={draw=none}
到轴选项。我使用了此答案中的 MWE如何反转 pgfplots 中 ylabels 的顺序
这是代码:
\documentclass{article}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\pgfplotstableread[header=true]{
one two three
A 2 0.3
B 3 0.4
C 4 0.5
D 5 0.6
E 4 0.7
F 3 0.6
G 2 0.5
H 3 0.4
I 4 0.3
J 5 0.4
K 4 0.5
L 3 0.6
M 2 0.7
N 3 0.6
}\data
\pgfplotsset{compat=newest, width=10cm, height=10cm}
\begin{document}
\begin{figure}[h!]
\centering
\begin{tikzpicture}
\begin{axis}[
xbar,
xmin=1,
xmax=6,
symbolic y coords={N,M,L,K,J,I,H,G,F,E,D,C,B,A},
ytick=data,
ytick style={draw=none}
]
\addplot [
error bars/.cd,
x dir = both,
x explicit,
] table [
x=two,
y=one,
x error = three
] {\data};
\end{axis}
\end{tikzpicture}
\caption{xbars and standard deviations}
\end{figure}
\end{document}