Wants to draw a dashed and horizontal line starts from y=98.23 (pointed in the attached image with an arrow)in a tikzpicture bar graph.
Following is the code
\documentclass[10pt,journal,compsoc]{IEEEtran}
\usepackage{pgfplots}
\usepackage{subfig}
\usetikzlibrary{positioning,shapes,arrows,shadows,patterns}
% correct bad hyphenation here
\hyphenation{op-tical net-works semi-conduc-tor}
\begin{document}
\begin{figure}
\centering
\captionsetup{justification = centering}
\subfloat[xxx]{
\label{11(a)}
\begin{tikzpicture}[scale =.5, transform shape]
\begin{axis}[
major x tick style = transparent,
ybar = 2*\pgflinewidth,
bar width=7pt,
ymajorgrids = true,
ylabel={xxx(\%)},
symbolic x coords={xx, yy, zz, ll},
xtick=data,
scaled y ticks = false,
enlarge x limits=0.25,
ymin=95,
minor y tick num=5,
xlabel style={yshift=-.3cm},
ylabel style={yshift=-.3cm},
tick label style={font=\footnotesize},
legend style={at={(.5,-0.1)}, anchor=north, /tikz/every even
column/.append style={column sep=.5cm}},
legend columns = -1,
]
\addplot[style = {fill=red, mark=none, postaction={pattern=dots}},
error bars/.cd, y dir=both, y explicit, error bar style ={thick}]
coordinates {
(xx, 97.772418) +- (0.00477703, 0.00477703)
(yy, 96.83437) +- (0.039005931, 0.039005931)
(zz, 96.9428) +- (0.05470002, 0.05470002)
(ll, 96.72381) +- (0.023826187, 0.023826187)};
\addplot[style = {fill=blue, mark=none, postaction={pattern=north
east lines}}, error bars/.cd, y dir=both, y explicit, error bar style =
{thick}]
coordinates {
(xx, 97.615588) +- (0.036178026, 0.036178026)
(yy, 96.77373) +- (0.045379505, 0.045379505)
(zz, 97.61842) +- (0.036159489, 0.036159489)
(ll, 96.64351) +- (0.044978336, 0.044978336)};
\addplot[style = {fill=green, mark=none, postaction=
{pattern=horizontal lines}}, error bars/.cd, y dir=both, y explicit, error
bar style ={thick}]
coordinates {
(xx, 98.856128) +- (0.031866164, 0.031866164)
(yy, 99.00258) +- (0.026840445, 0.026840445)
(zz, 98.02313) +- (0.057913644, 0.057913644)
(ll, 98.30856) +- (0.048969882, 0.048969882)};
\addplot[style = {fill=yellow, mark=none, postaction=
{pattern=vertical lines}}, error bars/.cd, y dir=both, y explicit, error bar
style ={thick}]
coordinates {
(xx, 97.778428) +- (0.035212399, 0.035212399)
(yy, 96.82722) +- (0.045398952, 0.045398952)
(zz, 97.75243) +- (0.034266698, 0.034266698)
(ll, 96.72982) +- (0.043016218, 0.043016218)};
\legend{xxx, xxx, xxx, xxx}
\end{axis}
\end{tikzpicture}
}
\end{figure}
\end{document}
Best Answer
Besides the given solution by Torbjørn T. in the comment below the question you could also add an
extra y tick
to achieve the desired result. The only tricky part is to move this line before the bars (when the "normal" grid lines should still be behind the bars).(I also "optimized" your code a bit which now should be simpler and hopefully more readable.)
For details please have a look at the comments in the code.