获取它的代码是
\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{tikz}
\usepackage{pgfplots,pgfplotstable}
\pgfplotsset{compat=1.12}
\usepackage{filecontents}
\begin{filecontents*}{a.dat}
experiment,1,2,3,4,5
V1-01,0.14,0.25,0.12,0.13,0.12
V1-02,0.08,0.07,0.12,0.13,0.12
V1-03,0.10,0.19,0.14,0.15,0.15
V2-01,0.11,0.23,0.08,0.10,0.09
V2-02,0.10,0.20,0.20,0.21,0.21
MH-03,0.16,0.18,0.21,0.21,0.19
MH-04,0.26,0.28,0.30,0.30,0.29
MH-05,0.37,0.41,0.40,0.41,0.39
MH-05,0.37,0.41,0.40,0.42,0.36
\end{filecontents*}
\pgfplotstableread[col sep=comma]{a.dat}\a
\begin{document}
\begin{tikzpicture}
\begin{axis}[width=9.5cm, height=5.5cm,
legend style={legend columns=-1, font=\tiny},
legend pos= north west,
xtick=data,
xticklabels from table={\a}{experiment},
xticklabel style = {font=\tiny,rotate=0},
ybar,
ybar interval=0.6,
enlargelimits=false,
ymin=0,ymax=0.45,
ytick={0,0.2,0.4,0.6,0.8},
yticklabel style={
/pgf/number format/fixed,
/pgf/number format/precision=2
}]
\addplot [color=blue,fill] table [x expr=\coordindex, y={1}] \a;
\addplot [color=yellow,fill] table [x expr=\coordindex, y={2}]\a;
\addplot [color=red,fill] table [x expr=\coordindex, y={3}] \a;
\addplot [color=green,fill] table [x expr=\coordindex, y={4}] \a;
\end{axis}
\end{tikzpicture}
\end{document}
如何增加用于分隔数据(例如 V1-01 和 V1-02)的灰线的宽度?
答案1
您指的是下面这样的情况吗?
% used PGFPlots v1.16
\documentclass[border=5pt]{standalone}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.12}
\usepackage{filecontents}
\begin{filecontents*}{a.dat}
experiment,1,2,3,4,5
V1-01,0.14,0.25,0.12,0.13,0.12
V1-02,0.08,0.07,0.12,0.13,0.12
V1-03,0.10,0.19,0.14,0.15,0.15
V2-01,0.11,0.23,0.08,0.10,0.09
V2-02,0.10,0.20,0.20,0.21,0.21
MH-03,0.16,0.18,0.21,0.21,0.19
MH-04,0.26,0.28,0.30,0.30,0.29
MH-05,0.37,0.41,0.40,0.41,0.39
MH-05,0.37,0.41,0.40,0.42,0.36
\end{filecontents*}
\pgfplotstableread[col sep=comma]{a.dat}\a
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width=9.5cm,
height=5.5cm,
legend style={legend columns=-1, font=\tiny},
legend pos= north west,
xtick=data,
xticklabels from table={\a}{experiment},
xticklabel style={font=\tiny,rotate=0},
ybar,
ybar interval=0.6,
enlargelimits=false,
ymin=0,ymax=0.45,
ytick={0,0.2,0.4,0.6,0.8},
yticklabel style={
/pgf/number format/fixed,
/pgf/number format/precision=2
},
% ---------------------------------------------------------------------
% added stuff
xtick pos=lower,
xtick style={
/pgfplots/major tick length=5mm,
},
% ---------------------------------------------------------------------
% (moved common options here)
table/x expr=\coordindex,
% ---------------------------------------------------------------------
]
\addplot [fill,color=blue] table [fill,y={1}] \a;
\addplot [fill,color=yellow] table [fill,y={2}] \a;
\addplot [fill,color=red] table [fill,y={3}] \a;
\addplot [fill,color=green] table [fill,y={4}] \a;
\end{axis}
\end{tikzpicture}
\end{document}