2

I noticed that the second \addplot does not recognize its xticks, I have tried the solution here but it does not work. enter image description here

\documentclass{report}
\usepackage{pgfplots}
\usepackage{tikz}



\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        width  = 0.85*\textwidth,
        height = 8cm,
        major x tick style = transparent,
        ybar=2*\pgflinewidth,
        bar width=14pt,
        ymajorgrids = true,
        ylabel = {Run time speed},
        symbolic x coords={Model 3, Model 5, Model 1, Model 4, Model 6, Model 2},
        xtick = data,
        x tick label style={rotate=90, anchor=east},
        bar shift=0pt,
        scaled y ticks = false,
        enlarge x limits=0.25,
        ymin=0,
        legend cell align=left,
        legend style={
                at={(1,1.05)},
                anchor=south east,
                column sep=1ex
        }
    ]



        \addplot[bar shift=0pt]
            coordinates {(Model 4, 1.0)
                         (Model 6, 1.0)
                         (Model 2, 1.0)};

        % This does not recognize x ticks.
        \addplot[bar shift=0pt]
            coordinates {(Model 3, 1.0)
                         (Model 5, 1.0)
                         (Model 1, 1.0)};

    \end{axis}
\end{tikzpicture}
\end{document}
  • Maybe have a look here, where a workaround is presented. – user121799 Aug 1 '18 at 14:00
  • 1
    To add a tick for all of the defined symbolic x coords, you can replace xtick=data by xtick distance=1,xtickmin={Model 3},xtickmax={Model 2},. – esdd Aug 1 '18 at 14:22
  • @esdd, it works, could you please at your comment as an answer so that I accept it? – Taha Magdy Aug 1 '18 at 14:29
1

If you want to add a tick for all of the defined symbolic x coords, you can replace xtick=data by

xtick distance=1,
xtickmin={Model 3},
xtickmax={Model 2},

Example:

\documentclass{report}
\usepackage{pgfplots}% loads tikz automatically
\pgfplotsset{compat=1.16}% added, current version is 1.16

\begin{document}
\begin{tikzpicture}
  \begin{axis}[
    width  = 0.85*\textwidth,
    height = 8cm,
    major x tick style = transparent,
    ybar=2*\pgflinewidth,
    bar width=14pt,
    ymajorgrids = true,
    ylabel = {Run time speed},
    symbolic x coords={Model 3, Model 5, Model 1, Model 4, Model 6, Model 2},
    xtick distance=1,% <- added
    xtickmin={Model 3},% <- added
    xtickmax={Model 2},% <- added
    x tick label style={rotate=90, anchor=east},
    bar shift=0pt,
    scaled y ticks = false,
    enlarge x limits=0.25,
    ymin=0,
    legend cell align=left,
    legend style={
            at={(1,1.05)},
            anchor=south east,
            column sep=1ex
      }
  ]

    \addplot[bar shift=0pt]
        coordinates {(Model 4, 1.0)
                     (Model 6, 1.0)
                     (Model 2, 1.0)};

    \addplot[bar shift=0pt]
        coordinates {(Model 3, 1.0)
                     (Model 5, 1.0)
                     (Model 1, 1.0)};
  \end{axis}
\end{tikzpicture}
\end{document}

Result:

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.