0

There are two tikz barcharts in this snippet. I'm able to display barcharts one after another but when i use subfigure/subfloat its giving an error

\documentclass[preprint,12pt,3p]{elsarticle}
\usepackage{graphicx}
\usepackage{float}

\usepackage{epstopdf}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{xcolor}
\usepackage{pgfplots}
\usepackage{tikz}
\pgfplotsset{compat=1.10}
\usetikzlibrary{decorations.pathreplacing}

\begin{document}

\begin{figure}[ht!]
    \centering
    \subfloat{
        \begin{tikzpicture}
    \begin{axis}[
        ybar,
        ymin=0,
        width  = 12cm,
        height = 5cm,
        bar width=5pt,
        ylabel={$\mathcal{J}$ of WM},
        nodes near coords,
        xticklabel style={rotate=90},
        xtick = data,
        table/header=false,
        table/row sep=\\,
        xticklabels from table={\footnotesize
          wells\\\footnotesize lemput\\\footnotesize wang\\\footnotesize proposed\\
          \footnotesize
          wells\\\footnotesize lemput\\\footnotesize wang\\\footnotesize proposed\\
          \footnotesize
          wells\\\footnotesize lemput\\\footnotesize wang\\\footnotesize proposed\\
          }{[index]0},
        enlarge y limits={value=0.2,upper}
      %  legend pos=north west
    ]
     \legend{1\%, 5\%}
    \addplot table[x expr=\coordindex,y index=0]{1\\2\\3\\4\\4\\2\\3\\4\\4\\2\\3\\4\\};
    \addplot table[x expr=\coordindex,y index=0]{3\\2\\8\\4\\4\\2\\3\\4\\4\\2\\3\\4\\};
    \pgfplotsinvokeforeach{0,3,4,7,8,11}{\coordinate(l#1)at(axis cs:#1,0);}
    \end{axis}
    \coordinate(bbs)at(current bounding box.south);
    \foreach[count=\i,evaluate={\s=int(4*\i-1)},evaluate={\e=int(4*(\i-1)}] \text in {Axial,Coronial,Sagittarial} 
      \draw[decorate,decoration=brace]([xshift=8pt]l\s|-bbs)--node[below=5pt]{\text}([xshift=-8pt]l\e|-bbs);
\end{tikzpicture}
    }
    % A blank line here like a new paragraph so next picture is placed below
    \subfloat{
         \begin{tikzpicture}
    \begin{axis}[
        ybar,
        ymin=0,
        width  = 12cm,
        height = 5cm,
        bar width=5pt,
        ylabel={$\mathcal{J}$ of WM},
        nodes near coords,
        xticklabel style={rotate=90},
        xtick = data,
        table/header=false,
        table/row sep=\\,
        xticklabels from table={\footnotesize
          wells\\\footnotesize lemput\\\footnotesize wang\\\footnotesize proposed\\
          \footnotesize
          wells\\\footnotesize lemput\\\footnotesize wang\\\footnotesize proposed\\
          \footnotesize
          wells\\\footnotesize lemput\\\footnotesize wang\\\footnotesize proposed\\
          }{[index]0},
        enlarge y limits={value=0.2,upper}
      %  legend pos=north west
    ]
     \legend{1\%, 5\%}
    \addplot table[x expr=\coordindex,y index=0]{1\\2\\3\\4\\4\\2\\3\\4\\4\\2\\3\\4\\};
    \addplot table[x expr=\coordindex,y index=0]{3\\2\\8\\4\\4\\2\\3\\4\\4\\2\\3\\4\\};
    \pgfplotsinvokeforeach{0,3,4,7,8,11}{\coordinate(l#1)at(axis cs:#1,0);}
    \end{axis}
    \coordinate(bbs)at(current bounding box.south);
    \foreach[count=\i,evaluate={\s=int(4*\i-1)},evaluate={\e=int(4*(\i-1)}] \text in {Axial,Coronial,Sagittarial} 
      \draw[decorate,decoration=brace]([xshift=8pt]l\s|-bbs)--node[below=5pt]{\text}([xshift=-8pt]l\e|-bbs);
\end{tikzpicture}
    }

    \caption{Accuracies Comparision}
    \end{figure}
\end{document}
  • Could you please add more details to your question? – Claudio Fiandrino Sep 1 '14 at 10:33
  • there are two tikz barcharts in this snippet. I'm able to display barcharts one after another but when i used subfigure/subfloat its giving an error.(i need some thing like subcaption). – madnavs Sep 1 '14 at 10:39
  • @NAV: It's better to add that explanation to the question itself than using a comment – user31729 Sep 1 '14 at 10:41
  • 1
    I'd just put them inside \begin{tabular}{c}...\end{tabular}. Judging from your examples, you want them on TOP of each other rather than BESIDE each other -- as they are too big to go side-by-side. – Andrew Sep 1 '14 at 10:51
  • 1
    @Andrew: Sometimes I find in some papers graphs totally unreadable. And there's no hope for them. However, by setting a good resolution in your PDF reader, if the graphs are done with TikZ, you can always scale the page to have the information readable. – Claudio Fiandrino Sep 1 '14 at 12:02
4

You have missed a parentheses (2 places) in

\foreach[count=\i,evaluate={\s=int(4*\i-1)},evaluate={\e=int(4*(\i-1)) %<-- this one, you have only one of them.

You forgot to load the subfig package which provides \subfloatcommand. Having said that, you can use the standard method of \resizebox:

\documentclass[preprint,12pt,3p]{elsarticle}
\usepackage{graphicx}
\usepackage{float}

\usepackage{epstopdf}
\usepackage{caption}
\usepackage{subfig}
\usepackage{xcolor}
\usepackage{pgfplots}
\usepackage{tikz}
\pgfplotsset{compat=1.10}
\usetikzlibrary{decorations.pathreplacing}

\begin{document}

\begin{figure}[ht!]
    \centering
    \subfloat[][Sub figure first]{\resizebox{0.5\textwidth}{!}{
        \begin{tikzpicture}
    \begin{axis}[
        ybar,
        ymin=0,
        width  = 12cm,
        height = 5cm,
        bar width=5pt,
        ylabel={$\mathcal{J}$ of WM},
        nodes near coords,
        xticklabel style={rotate=90},
        xtick = data,
        table/header=false,
        table/row sep=\\,
        xticklabels from table={\footnotesize
          wells\\\footnotesize lemput\\\footnotesize wang\\\footnotesize proposed\\
          \footnotesize
          wells\\\footnotesize lemput\\\footnotesize wang\\\footnotesize proposed\\
          \footnotesize
          wells\\\footnotesize lemput\\\footnotesize wang\\\footnotesize proposed\\
          }{[index]0},
        enlarge y limits={value=0.2,upper}
      %  legend pos=north west
    ]
     \legend{1\%, 5\%}
    \addplot table[x expr=\coordindex,y index=0]{1\\2\\3\\4\\4\\2\\3\\4\\4\\2\\3\\4\\};
    \addplot table[x expr=\coordindex,y index=0]{3\\2\\8\\4\\4\\2\\3\\4\\4\\2\\3\\4\\};
    \pgfplotsinvokeforeach{0,3,4,7,8,11}{\coordinate(l#1)at(axis cs:#1,0);}
    \end{axis}
    \coordinate(bbs)at(current bounding box.south);
    \foreach[count=\i,evaluate={\s=int(4*\i-1)},evaluate={\e=int(4*(\i-1))}] \text in {Axial,Coronial,Sagittarial}
      \draw[decorate,decoration=brace]([xshift=8pt]l\s|-bbs)--node[below=5pt]{\text}([xshift=-8pt]l\e|-bbs);
\end{tikzpicture}
    }}
    % A blank line here like a new paragraph so next picture is placed below
    \subfloat[][Sub figure second]{\resizebox{0.5\textwidth}{!}{
         \begin{tikzpicture}
    \begin{axis}[
        ybar,
        ymin=0,
        width  = 12cm,
        height = 5cm,
        bar width=5pt,
        ylabel={$\mathcal{J}$ of WM},
        nodes near coords,
        xticklabel style={rotate=90},
        xtick = data,
        table/header=false,
        table/row sep=\\,
        xticklabels from table={\footnotesize
          wells\\\footnotesize lemput\\\footnotesize wang\\\footnotesize proposed\\
          \footnotesize
          wells\\\footnotesize lemput\\\footnotesize wang\\\footnotesize proposed\\
          \footnotesize
          wells\\\footnotesize lemput\\\footnotesize wang\\\footnotesize proposed\\
          }{[index]0},
        enlarge y limits={value=0.2,upper}
      %  legend pos=north west
    ]
     \legend{1\%, 5\%}
    \addplot table[x expr=\coordindex,y index=0]{1\\2\\3\\4\\4\\2\\3\\4\\4\\2\\3\\4\\};
    \addplot table[x expr=\coordindex,y index=0]{3\\2\\8\\4\\4\\2\\3\\4\\4\\2\\3\\4\\};
    \pgfplotsinvokeforeach{0,3,4,7,8,11}{\coordinate(l#1)at(axis cs:#1,0);}
    \end{axis}
    \coordinate(bbs)at(current bounding box.south);
    \foreach[count=\i,evaluate={\s=int(4*\i-1)},evaluate={\e=int(4*(\i-1))}] \text in {Axial,Coronial,Sagittarial}
      \draw[decorate,decoration=brace]([xshift=8pt]l\s|-bbs)--node[below=5pt]{\text}([xshift=-8pt]l\e|-bbs);
\end{tikzpicture}
    }}
    \caption{Accuracies Comparision}
    \end{figure}
\end{document}

enter image description here

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.