Seite 1 von 1

Einzelner Balken im Balkendiagramm mit anderer Farbe

Verfasst: Di 22. Nov 2016, 17:17
von Thomas Tannert
Hallo Leute,

ich habe absolut keine Ahnung wie ich das hier lösen soll! Habt ihr eine Idee- gerne auch eine "dreckige" Lösung.
In meinem Beispiel hätte ich gerne, dass die beiden Balken bei "alle" eine dunklere Farbe haben. Sie müssen also nicht mal eine komplett andere farbe haben....
Hatte die Idee vlt. mit ybar stacked, aber da bekomme ich nicht mal zwei nebeneinanderliegende Balken hin....
\documentclass[12pt,a4paper,oneside]{scrreprt}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{color}
\usepackage{pgfplots}
\begin{document}


\begin{figure}[h]
\begin{tikzpicture}
\begin{axis}[
width = 15cm,
height = 8cm,
ybar,
ylabel={y-Wett},
symbolic x coords={Druck,alle,Bypass,Speisewasser,Rezirkulation},
xtick=data,
ymin = 0,
ymax = 180,
ytick = {0,20,...,180},
scaled ticks=false, 
tick label style={/pgf/number format/fixed},
/pgf/number format/1000 sep={},
legend style={at={(0.5,-0.15)},
anchor=north,legend columns=-1},
]
      \addplot coordinates 
      {
      (Druck,171.481)
      (Bypass,156.675)
      (Speisewasser,151.896)
      (Rezirkulation,147.301)
      (alle,164.483)
      }; 
      \addplot coordinates 
      {
      (Druck,145.178)
      (Bypass,158.066)
      (Speisewasser,167.66)
      (Rezirkulation,170.765)
      (alle,155.93)
      };          
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
Vielen Dank für eure Hilfe!

Verfasst: Mi 23. Nov 2016, 11:09
von esdd
Eine Möglichkeit:
\documentclass[12pt,a4paper,oneside]{scrreprt} 
\usepackage[ngerman]{babel} 
\usepackage[utf8]{inputenc} 
\usepackage{pgfplots}% lädt auch tikz, xcolor, graphicx, ...
\pgfplotsset{compat=newest}% immer eine Angabe für compat machen
\begin{document} 
\begin{figure}[htb] 
    \begin{tikzpicture}
        \pgfplotsset{
            every linear axis/.append style={
                width = 15cm,
                height = 8cm,
                ybar,
                symbolic x coords={Druck,alle,Bypass,Speisewasser,Rezirkulation}, 
                xmin=Druck,
                xmax=Rezirkulation,
                enlarge x limits={abs=30pt},
                ymin = 0,
                ymax = 180,
            }
        }
        \begin{axis}[ 
                ylabel={y-Wett}, 
                xtick=data,
                ytick = {0,20,...,180},
        % die weiteren Optionen werden für das Bespiel gar nicht gebraucht
                %scaled ticks=false,
                %tick label style={/pgf/number format/fixed}, 
                %/pgf/number format/1000 sep={},
                %legend style={at={(0.5,-0.15)},
                %anchor=north,legend columns=-1},
            ] 
            \addplot coordinates 
            { 
                (Druck,171.481) 
                (Bypass,156.675) 
                (Speisewasser,151.896) 
                (Rezirkulation,147.301) 
                (alle,164.483) 
            }; 
            \addplot coordinates 
            { 
                (Druck,145.178) 
                (Bypass,158.066) 
                (Speisewasser,167.66) 
                (Rezirkulation,170.765) 
                (alle,155.93) 
            };
        \end{axis}
        \begin{axis}[ 
                axis lines=none
            ] 
            \addplot+[fill=blue] coordinates 
            { 
                (alle,164.483) 
            }; 
            \addplot+[fill=red] coordinates 
            { 
                (alle,155.93) 
            };
        \end{axis}
    \end{tikzpicture}
\end{figure}
\end{document}

Verfasst: Do 24. Nov 2016, 11:44
von Thomas Tannert
Hey,
wow!

Vielen Dank!
Mein Bruder hat mir zwar auch eine Lösung angeboten, aber die ist wesentlich umständlicher!

Echt ein cooler Trick.....

Danke auch für die ganzen Hinweise.