4

I've been trying to do this there's a few days and the following code was the best that I got until now.

  1. This is supposed to be one graph;
  2. Because I say axis y line=none the last three "blocks" of the graph don't show the "ymajorgrids";
  3. Another problem are the "spaces" between the "blocks", I tried to solve this using the \hspace{3.7cm}, but if I keep the value small enough to looks like one graph, the bars between 30% and 10% will be too close from each other;
  4. I tried "groupplots" but "no lucky";
  5. If I use the \documentclass{standalone} I'm not able to view the entire graph.

Code:

\documentclass{article}
    \usepackage{tikz,pgfplots,rotating,mathpazo}
    \pgfplotsset{compat=1.13}
    %\usepackage[active,tightpage]{preview}
    %\PreviewEnvironment{tikzpicture}
    %\setlength\PreviewBorder{5pt}
\begin{document}
\begin{tikzpicture}[scale=0.60]
\pgfplotsset{scale only axis,}
\pgfplotsset{every axis legend/.append style={draw=none,
at={(0,-0.3)},
anchor=south,legend columns=-1}}

% Begin 30' Figure
\begin{axis}[
  xtick={10,20,30},
  xticklabels={$10\%$,$20\%$,$30\%$},
  axis y line*=left,
  ymin=0,ymax=0.035,
  xlabel=$30'$,
  ylabel=$MSE$,
  ybar, x=0.2cm, enlarge x limits={abs=0.75cm},
  ymajorgrids,
]
\addplot[black!100!white,fill=black!100!white,] 
  coordinates{(10,0.00495)(20,0.00418)(30,0.00565)};%\addlegendentry{$BP$}\label{HplotBP}
\addplot[black!15!white,fill=black!15!white,] 
  coordinates{(10,0.00241)(20,0.00233)(30,0.00234)};%\addlegendentry{$PSO$}\label{HplotPSO}
\addplot[black!50!white,fill=black!50!white,] 
  coordinates{(10,0.00240)(20,0.00233)(30,0.00241)};%\addlegendentry{$PSO-AWF$}\label{HplotPSO-AWF}        
\end{axis}
\begin{axis}[
  axis y line=none,
  axis x line=none,
  ymin=0,ymax=3000,
  ylabel=$Run$ $Time$ $(s)$,
  x=0.2cm, enlarge x limits={abs=0.75cm},
]
\addplot[smooth,mark=*,black!100!white] coordinates{(10,9.7409)(20,15.8253)(30,21.9555)};
\addplot[smooth,mark=*,black!15!white] coordinates{(10,856.4934)(20,1685.4893)(30,2508.6612)};
\addplot[smooth,mark=*,black!50!white] coordinates{(10,466.1263)(20,951.3380)(30,1328.8989)};
\end{axis}
% End 30' Figure
\hspace{3.7cm}% NO SPACE!
% Begin 1h Figure
\begin{axis}[
  xtick={10,20,30},
  xticklabels={$10\%$,$20\%$,$30\%$},
  axis y line=none,
  ymin=0,ymax=0.035,
  xlabel=$1h$,
  ylabel=$MSE$,
  ybar, x=0.2cm, enlarge x limits={abs=0.75cm},
  ymajorgrids,
]
\addplot[black!100!white,fill=black!100!white,] 
  coordinates{(10,0.01105)(20,0.00848)(30,0.01018)};%\addlegendentry{$BP$}\label{HplotBP}
\addplot[black!15!white,fill=black!15!white,] 
  coordinates{(10,0.00409)(20,0.00409)(30,0.00409)};%\addlegendentry{$PSO$}\label{HplotPSO}
\addplot[black!50!white,fill=black!50!white,] 
  coordinates{(10,0.00407)(20,0.00409)(30,0.00412)};%\addlegendentry{$PSO-AWF$}\label{HplotPSO-AWF}
\end{axis}
\begin{axis}[
  axis y line=none,
  axis x line=none,
  ymin=0,ymax=3000,
  ylabel=$Run$ $Time$ $(s)$,
  x=0.2cm, enlarge x limits={abs=0.75cm},
]
\addplot[smooth,mark=*,black!100!white] coordinates{(10,9.9127)(20,15.7465)(30,22.0166)};
\addplot[smooth,mark=*,black!15!white] coordinates{(10,846.4655)(20,1674.5623)(30,2488.7022)};
\addplot[smooth,mark=*,black!50!white] coordinates{(10,468.0651)(20,939.3421)(30,1312.1089)};
\end{axis}
% End 1h Figure
\hspace{3.7cm}% NO SPACE!
% Begin 3h Figure
\begin{axis}[
  xtick={10,20,30},
  xticklabels={$10\%$,$20\%$,$30\%$},
  axis y line=none,
  ymin=0,ymax=0.035,
  xlabel=$3h$,
  ylabel=$MSE$,
  ybar, x=0.2cm, enlarge x limits={abs=0.75cm},
  ymajorgrids,
]
\addplot[black!100!white,fill=black!100!white,] 
  coordinates{(10,0.02303)(20,0.02103)(30,0.01911)};%\addlegendentry{$BP$}\label{HplotBP}
\addplot[black!15!white,fill=black!15!white,] 
  coordinates{(10,0.01069)(20,0.01078)(30,0.01086)};%\addlegendentry{$PSO$}\label{HplotPSO}
\addplot[black!50!white,fill=black!50!white,] 
  coordinates{(10,0.01066)(20,0.01110)(30,0.01124)};%\addlegendentry{$PSO-AWF$}\label{HplotPSO-AWF}
\end{axis}
\begin{axis}[
  axis y line=none,
  axis x line=none,
  ymin=0,ymax=3000,
  ylabel=$Run$ $Time$ $(s)$,
  x=0.2cm, enlarge x limits={abs=0.75cm},
]
\addplot[smooth,mark=*,black!100!white] coordinates{(10,7.37)(20,14.57)(30,21.34)}; \addlegendentry{$BP$}
\addplot[smooth,mark=*,black!15!white] coordinates{(10,908.04)(20,1804.93)(30,2722.43)}; \addlegendentry{$PSO$}
\addplot[smooth,mark=*,black!50!white] coordinates{(10,428.61)(20,873.12)(30,1315.82)}; \addlegendentry{$PSO-AWF$}
\end{axis}
% End 3h Figure
\hspace{3.7cm}% NO SPACE!
% Begin 6h Figure
\begin{axis}[
  xtick={10,20,30},
  xticklabels={$10\%$,$20\%$,$30\%$},
  axis y line=none,  
  ymin=0,ymax=0.035,
  xlabel=$6h$,
  ylabel=$MSE$,
  ybar, x=0.2cm, enlarge x limits={abs=0.75cm},
  ymajorgrids,
]
\addplot[black!100!white,fill=black!100!white,] 
  coordinates{(10,0.03107)(20,0.02478)    (30,0.02055)};%\addlegendentry{$BP$}\label{HplotBP}
\addplot[black!15!white,fill=black!15!white,] 
  coordinates{(10,0.01616)(20,0.01617)(30,0.01729)};%\addlegendentry{$PSO$}\label{HplotPSO}
\addplot[black!50!white,fill=black!50!white,] 
  coordinates{(10,0.01589)(20,0.01640)(30,0.01653)};%\addlegendentry{$PSO-AWF$}\label{HplotPSO-AWF}
\end{axis}
\begin{axis}[
  axis y line*=right,
  axis x line=none,
  ymin=0,ymax=3000,
  ylabel=$Run$ $Time$ $(s)$,
  x=0.2cm, enlarge x limits={abs=0.75cm},
]
\addplot[smooth,mark=*,black!100!white] coordinates{(10,9.74)    (20,15.72)(30,22.11)};
\addplot[smooth,mark=*,black!15!white] coordinates{(10,852.99)(20,1676.16)(30,2505.78)};
\addplot[smooth,mark=*,black!50!white] coordinates{(10,443.05)(20,841.54)(30,1281.74)};
\end{axis}
% End 6h Figure
\end{tikzpicture}
\end{document}

enter image description here

1 Answer 1

3

How does this look? I positioned all the axes relative to each other, by giving them names and using e.g. at={(otheraxisname.north east)},anchor=north west. Also turned off the yticklabels on most of the axes, and set the tickwidth to zero.

Unrelated note: Don't use math mode for italics, if that's what you wanted with $Run$ $Time$. If italics was what you were after, use \textit{Run Time (s)}.

enter image description here

\documentclass{standalone}
\usepackage{pgfplots,rotating,mathpazo}
\pgfplotsset{compat=1.13}
\begin{document}
\begin{tikzpicture}[scale=0.60]
\pgfplotsset{scale only axis,
every axis legend/.append style={draw=none,
at={(0,-0.3)},
anchor=south,legend columns=-1}}

% Begin 30' Figure
\begin{axis}[
  xtick={10,20,30},
  xticklabels={$10\%$,$20\%$,$30\%$},
  axis y line*=left,tickwidth=0pt,
  ymin=0,ymax=0.035,
  xlabel=$30'$,
  ylabel=MSE,
  ybar, x=0.2cm, enlarge x limits={abs=0.75cm},
  ymajorgrids,
  name=ax1
]
\addplot[black!100!white,fill=black!100!white,] 
  coordinates{(10,0.00495)(20,0.00418)(30,0.00565)};%\addlegendentry{$BP$}\label{HplotBP}
\addplot[black!15!white,fill=black!15!white,] 
  coordinates{(10,0.00241)(20,0.00233)(30,0.00234)};%\addlegendentry{$PSO$}\label{HplotPSO}
\addplot[black!50!white,fill=black!50!white,] 
  coordinates{(10,0.00240)(20,0.00233)(30,0.00241)};%\addlegendentry{$PSO-AWF$}\label{HplotPSO-AWF}        
\end{axis}
\begin{axis}[
  at={(ax1.north east)},anchor=north east,
  axis y line=none,
  axis x line=none,
  ymin=0,ymax=3500,
  ylabel=Run Time$ (s),
  x=0.2cm, enlarge x limits={abs=0.75cm},
]
\addplot[smooth,mark=*,black!100!white] coordinates{(10,9.7409)(20,15.8253)(30,21.9555)};
\addplot[smooth,mark=*,black!15!white] coordinates{(10,856.4934)(20,1685.4893)(30,2508.6612)};
\addplot[smooth,mark=*,black!50!white] coordinates{(10,466.1263)(20,951.3380)(30,1328.8989)};
\end{axis}
% End 30' Figure
% Begin 1h Figure
\begin{axis}[
  at={(ax1.north east)},anchor=north west,name=ax2,
  xtick={10,20,30},
  xticklabels={$10\%$,$20\%$,$30\%$},
  y axis line style={draw=none},
  yticklabels={},tickwidth=0pt,scaled ticks=false,
  ymin=0,ymax=0.035,
  xlabel=1h,
  ybar, x=0.2cm, enlarge x limits={abs=0.75cm},
  ymajorgrids,
]
\addplot[black!100!white,fill=black!100!white,] 
  coordinates{(10,0.01105)(20,0.00848)(30,0.01018)};%\addlegendentry{$BP$}\label{HplotBP}
\addplot[black!15!white,fill=black!15!white,] 
  coordinates{(10,0.00409)(20,0.00409)(30,0.00409)};%\addlegendentry{$PSO$}\label{HplotPSO}
\addplot[black!50!white,fill=black!50!white,] 
  coordinates{(10,0.00407)(20,0.00409)(30,0.00412)};%\addlegendentry{$PSO-AWF$}\label{HplotPSO-AWF}
\end{axis}
\begin{axis}[
  at={(ax2.north west)},anchor=north west,
  axis y line=none,
  axis x line=none,
  ymin=0,ymax=3500,
  ylabel=Run Time (s),
  x=0.2cm, enlarge x limits={abs=0.75cm},
]
\addplot[smooth,mark=*,black!100!white] coordinates{(10,9.9127)(20,15.7465)(30,22.0166)};
\addplot[smooth,mark=*,black!15!white] coordinates{(10,846.4655)(20,1674.5623)(30,2488.7022)};
\addplot[smooth,mark=*,black!50!white] coordinates{(10,468.0651)(20,939.3421)(30,1312.1089)};
\end{axis}
% End 1h Figure
% Begin 3h Figure
\begin{axis}[
  at={(ax2.north east)},anchor=north west,name=ax3,
  xtick={10,20,30},
  xticklabels={$10\%$,$20\%$,$30\%$},
  y axis line style={draw=none},
  yticklabels={},tickwidth=0pt,scaled ticks=false,
  ymin=0,ymax=0.035,
  xlabel=3h,
  ybar, x=0.2cm, enlarge x limits={abs=0.75cm},
  ymajorgrids,
]
\addplot[black!100!white,fill=black!100!white,] 
  coordinates{(10,0.02303)(20,0.02103)(30,0.01911)};%\addlegendentry{$BP$}\label{HplotBP}
\addplot[black!15!white,fill=black!15!white,] 
  coordinates{(10,0.01069)(20,0.01078)(30,0.01086)};%\addlegendentry{$PSO$}\label{HplotPSO}
\addplot[black!50!white,fill=black!50!white,] 
  coordinates{(10,0.01066)(20,0.01110)(30,0.01124)};%\addlegendentry{$PSO-AWF$}\label{HplotPSO-AWF}
\end{axis}
\begin{axis}[
  at={(ax3.north east)},anchor=north east,
  axis y line=none,
  axis x line=none,
  ymin=0,ymax=3500,
  ylabel=Run Time (s),
  x=0.2cm, enlarge x limits={abs=0.75cm},
]
\addplot[smooth,mark=*,black!100!white] coordinates{(10,7.37)(20,14.57)(30,21.34)}; \addlegendentry{$BP$}
\addplot[smooth,mark=*,black!15!white] coordinates{(10,908.04)(20,1804.93)(30,2722.43)}; \addlegendentry{$PSO$}
\addplot[smooth,mark=*,black!50!white] coordinates{(10,428.61)(20,873.12)(30,1315.82)}; \addlegendentry{$PSO-AWF$}
\end{axis}
% End 3h Figure
% Begin 6h Figure
\begin{axis}[
  at={(ax3.north east)},anchor=north west,name=ax4,
  xtick={10,20,30},
  xticklabels={$10\%$,$20\%$,$30\%$},
  y axis line style={draw=none},
  yticklabels={},tickwidth=0pt,scaled ticks=false,
  ymin=0,ymax=0.035,
  xlabel=6h,
  ybar, x=0.2cm, enlarge x limits={abs=0.75cm},
  ymajorgrids,
]
\addplot[black!100!white,fill=black!100!white,] 
  coordinates{(10,0.03107)(20,0.02478)    (30,0.02055)};%\addlegendentry{$BP$}\label{HplotBP}
\addplot[black!15!white,fill=black!15!white,] 
  coordinates{(10,0.01616)(20,0.01617)(30,0.01729)};%\addlegendentry{$PSO$}\label{HplotPSO}
\addplot[black!50!white,fill=black!50!white,] 
  coordinates{(10,0.01589)(20,0.01640)(30,0.01653)};%\addlegendentry{$PSO-AWF$}\label{HplotPSO-AWF}
\end{axis}
\begin{axis}[
  at={(ax3.north east)},anchor=north west,
  axis y line*=right,
  axis x line=none,
  ymin=0,ymax=3500,
  ylabel=Run Time (s),
  x=0.2cm, enlarge x limits={abs=0.75cm},
]
\addplot[smooth,mark=*,black!100!white] coordinates{(10,9.74)    (20,15.72)(30,22.11)};
\addplot[smooth,mark=*,black!15!white] coordinates{(10,852.99)(20,1676.16)(30,2505.78)};
\addplot[smooth,mark=*,black!50!white] coordinates{(10,443.05)(20,841.54)(30,1281.74)};
\end{axis}
% End 6h Figure

\draw [very thin] (ax1.north east) -- (ax4.north east);
\end{tikzpicture}
\end{document}
1
  • It's perfect! I learned new things with your code! Thank you!
    – Erick
    Jan 22, 2016 at 8:43

You must log in to answer this question.

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