1

I want to plot these two stacked bar plots as a subplot in one figure next to each other here is the code and my current output

enter image description here

\begin{figure}[htbp]

\centering

\subfigure[Weight comparison]{\begin{tikzpicture}

\begin{axis}[ylabel= Weight (tonne)
,ymin=0,ybar stacked,bar width=1cm,
y tick label style={/pgf/number format/fixed, 
/pgf/number format/1000 sep = \thinspace % Optional if you want to replace comma as the 1000 separator}, xtick=data,x=3.1cm,enlarge x limits=1,area legend,
symbolic x coords={Hybrid fuel cell , 4-stroke system} , legend style={draw=none, legend columns=-1}, width=3cm, height=9cm, legend pos=north west, font=\small]

\addplot coordinates
{(Hybrid fuel cell,0.375) (4-stroke system,0)};

\addplot coordinates
{(Hybrid fuel cell,8.885) (4-stroke system,0)};


\addplot coordinates
{(Hybrid fuel cell,3.9) (4-stroke system,0)};

\addplot coordinates
{(Hybrid fuel cell,0) (4-stroke system,13.064)};


\legend{FC, battery, Motor, DE}
\end{axis}
\end{tikzpicture}}

\subfigure[Volume comparison]{\begin{tikzpicture}

\begin{axis}[ylabel= Volume ($m^{3}$)
,ymin=0,ybar stacked,bar width=1cm,
y tick label style={/pgf/number format/fixed, 
/pgf/number format/1000 sep = \thinspace % Optional if you want to replace comma as the 1000 separator  }, xtick=data,x=3.1cm,enlarge x limits=1,
area legend, symbolic x coords={Hybrid fuel cell, 4-stroke system} , legend style={draw=none, legend columns=-1}, width=3cm, height=9cm, legend pos=north west, font=\small]

\addplot coordinates
{(Hybrid fuel cell,0.66) (4-stroke system,0)};

\addplot coordinates
{(Hybrid fuel cell,4.44) (4-stroke system,0)};


\addplot coordinates
{(Hybrid fuel cell,11.12) (4-stroke system,0)};

\addplot coordinates
{(Hybrid fuel cell,0) (4-stroke system,28.424)};


\legend{FC, battery, Motor, DE}

\end{axis}

\end{tikzpicture}}

\caption{Weight and volume of hybrid fuel cell system compared to 4-stroke diesel engine system}

\end{figure}
  • Your code is not complete. Please submit the full version from \documentclass to \end{document} – Symbol 1 Dec 31 '14 at 12:52
  • 2
    Your problem is completely unrelated to TikZ. You have added a paragraph break (an empty line) between your two subfigures, so the second one is on the line after the first one, i.e. below. Remove that empty line. Basically same problem as Minipage: 2 tables side by side isn't working If they're too wide to fit in one line, set the width of both axis to some small enough value. – Torbjørn T. Jun 15 '15 at 19:13

0 Answers0