I'm trying to create a stacked bar chart with different shades of grey/black for the bars. My code is as follows. This does change the colour of the bars. However the outline of the bars remains in the standard red/blue scheme and this is also what appears in the legend. How do I change the colour scheme altogether?
Thanks, Polly.
\begin{figure}[h]
\caption{Graph showing the proportion of children born into each partnership
scenario by ethnic group (Table 5, Kiernan and Smith, 2003)}
\centering
\begin{tikzpicture}
\begin{axis}[
ybar stacked,
legend style={at={(0.5,-0.35)},
anchor=north,legend columns=-1},
x axis line style = { opacity = 0 },
y axis line style = { opacity = 0 },
tickwidth = 0pt,
bar width=10pt,
ylabel={\% of births},
symbolic x coords={White British, Mixed Ethnicity, Indian, Pakistani,
Bangladeshi, African Caribbean, Other Black, Other},
xtick=data,
x tick label style={rotate=45,anchor=east},
]
\addplot+[ybar] plot coordinates {(White British,14.4) (Mixed Ethnicity,38)
(Indian,7.3) (Pakistani,7) (Bangladeshi,9.3)(African Caribbean,51.6) (Other
Black,39.4) (Other,14.3)} [fill=gray!90];
\addplot+[ybar] plot coordinates {(White British,27.1) (Mixed
Ethnicity,21.4)
(Indian,1.9) (Pakistani,1.1) (Bangladeshi,2.9)(African Caribbean,16.3)
(Other Black,14.2) (Other,9.8)} [fill=gray!50];
\addplot+[ybar] plot coordinates {(White British,58.5) (Mixed
Ethnicity,40.6)
(Indian,90.0) (Pakistani,91.9) (Bangladeshi,87.8)(African Caribbean,32)
(Other Black,46.5) (Other,75.9)} [fill=gray!10];
\legend{Single, Cohabiting, Married}
\end{axis}
\end{tikzpicture}
\end{figure}
Best Answer
Don't use
What you should use is
(Which tutorial teaches users to do
\addplot plot
anyways?)To set the colour of the border, use
draw=<colour>
in addition tofill=<colour>
. For example\addplot [fill=gray!90,draw=black!70] coordinates
. Because you haveybar stacked
in theaxis
options, you don't have to specifyybar
for each plot.Alternatively, define a custom
cycle list
in theaxis
options, and don't set any options for each\addplot
. I.e. addto the
axis
options, and use justOutput as above.