10

I am creating a stacked barchart with the following code. However, I have some problems.

  • How do I set the width, of the whole thing? width= does not do it ...
  • How can I get thicker bars?
  • How can I get them narrower?

Code:

\begin{figure}
\begin{tikzpicture}
\begin{axis}[xbar stacked,
%legend cell align=left,
legend style={legend columns=4,at={(0,-0.2)},anchor=north west,draw=none},
yticklabels={Chromium 16, Firefox 9, Internet Explorer 9, Internet Explorer 8},
xmin=0,
]
%Chrome   Firefox  IE 9     IE 8
\addplot coordinates
% Transfer
{(0.38,0) (0.07,1) (0.12,2) (1,3)};
\addplot coordinates
% Database
{(6.99,0) (6.99,1) (6.98,2) (6.95,3)};
\addplot coordinates
% Transfer
{(0.04,0) (0.04,1) (0.08,2) (0.23,3)};
\addplot coordinates
% Rendering
{(1.8,0) (2.38,1) (6,2) (14.66,3)};
\legend{Transfer,Database,Transfer,Rendering}
\end{axis}
\end{tikzpicture}
\caption{Performance}
\label{fig:perf}
\end{figure}

1 Answer 1

15

You can get thicker bars using

bar width=<whatever you want>

You can set the width of the plot using

width=<whatever you want>

I generally specify my width in terms of \textwidth so that it scales appropriately if the dimensions of the page change, but there's nothing to stop you from using a static measurement (such as 8cm).

enter image description here

In the code below, I also specified your ytick={0,1,2,3} so that the yticklabels behaved correctly.

\documentclass{article}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[xbar stacked,bar width=40, % NEW BIT
%legend cell align=left,
legend style={legend columns=1,at={(1,1)},anchor=north west},
ytick={0,1,2,3},  % NEW BIT
yticklabels={Chromium 16, Firefox 9, Internet Explorer 9, Internet Explorer 8},
xmin=0,
width=.75\textwidth, % NEW BIT
]
%Chrome   Firefox  IE 9     IE 8
\addplot coordinates
% Transfer
{(0.38,0) (0.07,1) (0.12,2) (1,3)};
\addplot coordinates
% Database
{(6.99,0) (6.99,1) (6.98,2) (6.95,3)};
\addplot coordinates
% Transfer
{(0.04,0) (0.04,1) (0.08,2) (0.23,3)};
\addplot coordinates
% Rendering
{(1.8,0) (2.38,1) (6,2) (14.66,3)};
\legend{Transfer,Database,Transfer,Rendering}
\end{axis}
\end{tikzpicture}


\end{document}
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .