5

To outline a path in white, one usually the draw the path larger and fill it in white, then copies the original path filled in black over it. This is to better separate it from the background.

But this does not work in pgfplots of course. If one \addplots a copy of the graph colored in white, with line width= greater than the intended graph, the original graph is shifted, so they cannot overlap to give a white outline of each (black) bar.

QUESTION 1: How do I get pgfplots to outline each bar in a bar graph in white in addition to its black outline (which remains black)?

(QUESTION 2 (answered in the comments already): How is the horizontal distance between the first bar and the Y-axis scaled?)

For example, how does one do all this in :

\documentclass{standalone}\usepackage{pgfplots,tikz}
\begin{document}\begin{tikzpicture}\pgfplotsset{%
every axis legend/.append style={at={(0.9,0.7)},anchor=south east}}%
\draw[draw=none,fill=black!20]rectangle(13.4,13.4);
\begin{axis}[title={},grid=major,scaled y ticks=false,
bar width=12.34pt,line width=3.2pt,%
enlarge x limits={true,abs value=0.64},
width=428pt,x tick style={line width=2.4pt,draw=black},%
height=428pt,y tick style={line width=2.4pt,draw=black},%
ybar=8pt,%BAR SEPARATION
yticklabel style={/pgf/number format/fixed,/pgf/number format/precision=3},%
xtick=\empty,xtick={1,...,3},xticklabels={%
    \textbf{A},%
    \textbf{B},%
    \textbf{C},%
},legend style={inner xsep=8pt,inner ysep=4pt,line width=2pt,draw=none,minimum height=22pt,column sep=4pt},% remove this to show the legend border
legend image code/.code={\draw[#1](-6pt,-6pt)rectangle(6pt,6pt);}%
]%
\addplot[fill=blue60!,draw=black,
point meta=y,
every node near coord/.style={inner ysep=8pt},
error bars/.cd,y dir=both,
y explicit]table[y error=error]{%
x   y       error    label
1   19.9    2           1
2   38.6    3           2
3   35.2    3           3
};%LEGEND
\legend{\makebox[64pt]{\raisebox{-2pt}{MyLabelGoesHereYes}},}
\end{axis}\end{tikzpicture}\end{document}

edit : perhaps it can be done via decorations ?

  • 1
    For 1b, see enlarge x limits on page 273 of the 1.11 manual – darthbith Sep 30 '14 at 20:51
  • I added the suggested enlarge x limits command into the MWE with an appropriate value, as suggested. Now to figure out how to give a white outline to each bar. – Guido Jorg Sep 30 '14 at 22:05
7

You can add preaction={draw=white, line width=5pt} to the \addplot [...] options to get a white outline:

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    ybar,
    axis background/.style={fill=gray},
    axis on top
]
\addplot [fill=yellow, draw=black, very thick, preaction={draw=white, line width=5pt}] table {%
x   y
1   19.9
2   38.6
3   35.2
};
\end{axis}
\end{tikzpicture}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.