4

I've got a bar chart with two main bars (black, x ticks). Each of the two bars is specified by several different sub-bars (filled resp. pattern). As the first bar at x-coordinate 1 is described by other sub-bars as the second bar at x-coordinate 2 pgfplots leaves messy space, which I don't want to appear.

\documentclass[border=9,tikz]{standalone}
    \usepackage{pgfplots}
        \pgfplotsset{compat=1.14}

\begin{document}
    \begin{tikzpicture}
        \begin{axis}[ybar,enlarge x limits=.5]
            \addplot[fill=magenta]coordinates{(1,9) (2,8)};
            \addplot[fill=red    ]coordinates{(1,7)};
            \addplot[fill=yellow ]coordinates{(1,4)};
            \addplot[fill=green  ]coordinates{(2,6)};
            \addplot[fill=cyan   ]coordinates{(2,4)};
            \addplot[fill=blue   ]coordinates{(2,3)};
            \legend{1,2,3,4,5,6}
        \end{axis}
    \end{tikzpicture}
\end{document}

Old description and code

Now I want to move the three Bars (Nr. 4,5,6) as close to the black bar as the bars are at x-tick "One".

Is there any possibility to shift those 3 bars 28pt (= 2* 5pt + 2* 2,5pt + 5pt space of two bars and respective interbarspace) to the left?

Here is my MWE:

\documentclass{article}

\usepackage[ngerman]{babel}
\usepackage[ansinew]{inputenc}                              
\usepackage[T1]{fontenc}  
\usepackage{tikz,pgf}
\usepackage{pgfplots}
\usepackage{float}                                                  

\usepgfplotslibrary{dateplot, statistics}
\usetikzlibrary{patterns}

\pgfplotsset{compat=1.8,legend style={cells={anchor=west},
 legend pos=outer north east}

\begin{document}

\begin{figure}[H]
\centering
\begin{tikzpicture}
\begin{axis}[%
    ybar=5pt,
    xtick={1,2,3},
    x tick style={xshift=-28pt},
    ytick={0,1,2,3,4,5,6,7,8,9,10},
    xticklabels={One,Two},
    x tick label style={xshift=-28pt},
    ymin=0,
    ymax=10,
    xmin=0.45,
    xmax=2.35,
    width=0.9\linewidth,
    height=5cm,
    nodes near coords, nodes near coords align={vertical},
    enlarge y limits={value=0.1,upper},
    bar width=9pt,
]
\addplot[%
    draw=black,
    fill=black
    ] coordinates
    {(1,9) (2,8)};

\addplot[%
    draw=black,
    fill=white
    ] coordinates
    {(1,7)};

\addplot[%
    draw=black,
    fill=lightgray
    ] coordinates
    {(1,4)};

\addplot[%
    draw=black,
    pattern=north west lines
    ] coordinates
    {(2,6)};

\addplot[%
    draw=black,
    pattern=dots
    ] coordinates
    {(2,4)};

\addplot[%
    draw=black,
    pattern=horizontal lines
    ] coordinates
    {(2,3)};

\legend{Main Bars, Bar 1,Bar 2,Bar 3,Bar 4,Bar 5}

\end{axis}
\end{tikzpicture}

\end{figure}

\end{document} 

2
  • 1
    This is not really minimum. Have of your code is just visual settings. While i understand that you need them, they are not relevant for this problem. I know its not that important, but help us helping you. Nobody wants to look over lines that don't matter.
    – pschulz
    Commented Nov 9, 2016 at 23:43
  • Duplicate? tex.stackexchange.com/questions/43832/… Commented Jul 3, 2018 at 7:54

0

You must log in to answer this question.

Browse other questions tagged .