1

I have created a bar diagram similar to: How to create symbolic x coords without losing last bar

But at a certain width the symbolic x coords are plotted twice. How can I manage the x axis correctly?

Here is my mini example:

\documentclass[12pt,a4paper,]{scrartcl}
\usepackage{a4wide}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage[miktex]{gnuplottex} 
\usepackage{pgfplots}



\begin{document}
    \begin{figure}
        \begin{tikzpicture}
        \begin{axis}[%
        width=1\linewidth,
        height=0.5\linewidth,
        axis x line=center,
        axis y line=left,
        symbolic x coords={CP-Schelle,Mistel-Schelle V2,Mistel-Schelle V4,Mistel-Schelle V4.2D,Gewickelt nach Inspire},
        enlargelimits=true,
        ymin=0,
        nodes near coords,
        x tick label style={
        font=\small,
        text width=1cm,
        align=center
        },
        ybar]
        \addplot[color=gray, fill] coordinates {(CP-Schelle,1.000)};
        \addplot[color=blue, fill] coordinates {(Mistel-Schelle V2,2.459)(Mistel-Schelle V4,3.318)(Mistel-Schelle V4.2D,2.243)(Gewickelt nach Inspire,1.782)};
        \end{axis}
        \end{tikzpicture}
    \end{figure}

    \begin{figure}
        \begin{tikzpicture}
        \begin{axis}[%
        width=0.6\linewidth,
        height=0.5\linewidth,
        axis x line=center,
        axis y line=left,
        symbolic x coords={CP-Schelle,Mistel-Schelle V2,Mistel-Schelle V4,Mistel-Schelle V4.2D,Gewickelt nach Inspire},
        enlargelimits=true,
        ymin=0,
        nodes near coords,
        x tick label style={
            font=\small,
            text width=1cm,
            align=center
        },
        ybar]
        \addplot[color=gray, fill] coordinates {(CP-Schelle,1.000)};
        \addplot[color=blue, fill] coordinates {(Mistel-Schelle V2,2.459)(Mistel-Schelle V4,3.318)(Mistel-Schelle V4.2D,2.243)(Gewickelt nach Inspire,1.782)};
        \end{axis}
        \end{tikzpicture}
    \end{figure}

\end{document}
  • 1
    Welcome to TeX.SX. If you have PGFPlots v1.13 or newer add xtick distance=1 to the axis options. – Stefan Pinnow Jan 19 '17 at 15:52
  • @StefanPinnow an answer? :) – cmhughes Jan 19 '17 at 16:25
2

Here is the answer which was asked for.

\documentclass[border=5pt]{standalone}
\usepackage[ngerman]{babel}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        width=1\linewidth,
        height=0.5\linewidth,
        axis x line=center,
        axis y line=left,
        symbolic x coords={
            CP-Schelle,
            Mistel-Schelle V2,
            Mistel-Schelle V4,
            Mistel-Schelle V4.2D,
            Gewickelt nach Inspire
        },
        enlargelimits=true,
        ymin=0,
        nodes near coords,
        x tick label style={
            font=\small,
            text width=1cm,
            align=center,
        },
        ybar,
        xtick distance=1,               % <-- added
        % use comma as decimal separator
        % (because the x tick labels are (also) in German)
        /pgf/number format/use comma,   % <-- added
    ]
        \addplot [fill,gray] coordinates {
            (CP-Schelle,1.000)
        };
        \addplot [fill,blue] coordinates {
            (Mistel-Schelle V2,2.459)
            (Mistel-Schelle V4,3.318)
            (Mistel-Schelle V4.2D,2.243)
            (Gewickelt nach Inspire,1.782)
        };
    \end{axis}
\end{tikzpicture}
\end{document}

image showing the result of above code

  • If this answer suits your needs you could -- besides upvoting it -- think of accepting it (by clicking on the checkmark ✓ next to the answer). By that it disappears from the "still an open question" list. If you need further assistance please edit your question accordingly or ask a Follow-up question. Thanks. – Stefan Pinnow Jan 21 '17 at 13:15

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.