1

My x-axis value disappears if the bar graph is not complete:

\begin{tikzpicture}
    \begin{axis}[
    every axis plot post/.style={/pgf/number format/fixed},
    ybar = 5pt,
    bar width=12pt,
    x=1.75cm,
    ymin = 1,
    %ymax = 1000,
    ymode = log,
    axis on top,
    xtick=data,
    enlarge x limits=0.2,
    symbolic x coords={100, 250, 500, 1000},
    %restrict y to domain*=0:1200, % Cut values off at 14
    visualization depends on=rawy\as\rawy, % Save the unclipped values
    after end axis/.code={ % Draw line indicating break
        \draw [ultra thick, white, decoration={snake, amplitude=1pt}, decorate] (rel axis cs:0,1.05) -- (rel axis cs:1,1.05);
    },
    nodes near coords={%
        \pgfmathprintnumber[sci, sci superscript, precision=2]{\rawy}% Print unclipped values
    },
    axis lines*=left,
    clip=false,
    ylabel={runtime [ms]},
    xlabel={image size [edge]},
    tick label style={font=\footnotesize},
    legend style={at={(0.5,-0.22)},
        anchor=north,legend columns=-1},
    ]    
    \addplot coordinates {(100, 340) (250, 5716) (500, 50669)};
    \addplot coordinates {(100, 21.25) (250, 331.97) (500, 2722) (1000,21877)};
    \addplot coordinates {(100, 15.77) (250, 158.15) (500, 1287) (1000,13224)};

    \legend{Conventional, Separated, Separated with SIMD}

    \end{axis}
    \end{tikzpicture}

I just can't see the value 1000 on the x-axis because there are only 3 values for one group

  • 1
    Instead of xtick=data, use xtick={100, 250, 500, 1000},. – user121799 Sep 4 '18 at 23:33
2

One minimal effort fix is to use xtick={100, 250, 500, 1000} instead of xtick=data.

\documentclass[border=3.14mm,tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
    every axis plot post/.style={/pgf/number format/fixed},
    ybar = 5pt,
    bar width=12pt,
    x=1.75cm,
    ymin = 1,
    %ymax = 1000,
    ymode = log,
    axis on top,
    %xtick=data,
    xtick={100, 250, 500, 1000},
    enlarge x limits=0.2,
    symbolic x coords={100, 250, 500, 1000},
    %restrict y to domain*=0:1200, % Cut values off at 14
    visualization depends on=rawy\as\rawy, % Save the unclipped values
    after end axis/.code={ % Draw line indicating break
        \draw [ultra thick, white, decoration={snake, amplitude=1pt}, decorate] (rel axis cs:0,1.05) -- (rel axis cs:1,1.05);
    },
    nodes near coords={%
        \pgfmathprintnumber[sci, sci superscript, precision=2]{\rawy}% Print unclipped values
    },
    axis lines*=left,
    clip=false,
    ylabel={runtime [ms]},
    xlabel={image size [edge]},
    tick label style={font=\footnotesize},
    legend style={at={(0.5,-0.22)},
        anchor=north,legend columns=-1},
    ]    
    \addplot coordinates {(100, 340) (250, 5716) (500, 50669)};
    \addplot coordinates {(100, 21.25) (250, 331.97) (500, 2722) (1000,21877)};
    \addplot coordinates {(100, 15.77) (250, 158.15) (500, 1287) (1000,13224)};

    \legend{Conventional, Separated, Separated with SIMD}

    \end{axis}
\end{tikzpicture}
\end{document}  

enter image description here

0

The reason why the 1000 is not shown is, that xtick=data (only) plots the xticks of the first \addplot command, which doesn't contain a corresponding coordinate.

To overcome this issue I present three options as solutions, from which option 1 is already presented in Marmot's answer (but unfortunately without any explanation where OPs issue is coming from).

Nonetheless in this case this should be the simplest solution, because a simple copy/paste replacement of data with the symbolic x coords values solves the issue. Option 2 adds a dummy \addplot containing all coordinates and option 3 suggests to reorder the \addplot commands thus that one containing all coordinates is stated first (and of course the legend entries have to be reordered as well then).

Please note that I have removed all unrelated code so one is not distracted. For more details please have a look at the comments in the code.)

% used PGFPlots v1.16
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        ybar,
        ymin=1,
        ymode=log,
        % option 1:
        % just make `xtick' and `symbolic x coords' contain the same values
        xtick=data,
%        xtick={100, 250, 500, 1000},
        symbolic x coords={100, 250, 500, 1000},
        enlarge x limits=0.2,
    ]

        % option 2:
        % add a dummy "forget plot" plot that contains all symbolic coords
        % `forget plot' doesn't increase the `cycle list index' and does not
        % count for the legend entries
        \addplot [
            forget plot,
            draw=none,
        ] coordinates {(100,100) (250,100) (500,100) (1000,100)};

        \addplot coordinates {(100, 340) (250, 5716) (500, 50669)};
        % option 3:
        % make one of the plots that contains all the symbolic coords the first
        % `\addplot' command (and don't forget to adapt the legend entries
        % accordingly)
        \addplot coordinates {(100, 21.25) (250, 331.97) (500, 2722) (1000,21877)};
        \addplot coordinates {(100, 15.77) (250, 158.15) (500, 1287) (1000,13224)};

        \legend{
            Conventional,
            Separated,
            Separated with SIMD,
        }
    \end{axis}
\end{tikzpicture}
\end{document}

image showing the result of above code

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.