von Zoid » Mi 22. Sep 2021, 18:33
Gast. hat geschrieben: ↑Mi 22. Sep 2021, 18:20
Würde ich bei ybar stacked nicht empfehlen, weil die Zahl der grünen Balken dann in den roten Balken steht, was etwas verwirrt, ähnlich hier:
\documentclass{scrreprt}
\usepackage{biblatex} % Literaturverzeichnis mit Datei
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{figure}[htb]
\centering
\begin{tikzpicture}
\pgfplotsset{/pgf/number format/.cd, fixed, assume math mode}
\pgfkeys{/pgf/number format/use comma}
\pgfmathsetlengthmacro\balkenbreite{20mm}
\definecolor{ha}{HTML}{75C36C}
\definecolor{ton}{HTML}{F78181}
\pgfplotstableread[col sep=comma]{
x, yton, yha
1 , 555 , 0
1 , 0 , 55
2 , 500 , 0
2 , 0 , 70
}\data
\begin{axis}[
width=5cm,
height=5cm,
axis x line=bottom,
axis y line=left,
ybar,
nodes near coords,
xtick={data},
x tick label style={rotate=90},
xticklabels={X,Z},
xmax=3,
ymin=0,
ymax=600,
ytick={0,100,200,300,400,500},
enlarge x limits=0.25,
legend entries={A, B},
ylabel style={align=center}, ylabel={Test},
ymajorgrids
]
\addplot [fill=ton,bar shift=0.025\balkenbreite,bar width=0.5\balkenbreite,font=\footnotesize] table [y=yton] {\data};
\addplot [fill=ha,bar shift=-0.025\balkenbreite,bar width=0.5*\balkenbreite,font=\footnotesize] table [y=yha] {\data};
\end{axis}
\end{tikzpicture}
\caption{Test2}
\end{figure}
\end{document}
Die originalen Zahlenwerte sind für die niedrigen Säulen eher gering, sodass sie gar nicht in die Balken passen. Durch die gewählten Beispielzahlen sieht es hier etwas anders aus. Falls es jedoch zu verwirrend sein sollte, dann würde ich ggf. mit Farben arbeiten, um den Unterschied deutlich zu machen.
[quote=Gast. post_id=116966 time=1632327641]
Würde ich bei [tt]ybar stacked[/tt] nicht empfehlen, weil die Zahl der grünen Balken dann in den roten Balken steht, was etwas verwirrt, ähnlich hier:
[code]\documentclass{scrreprt}
\usepackage{biblatex} % Literaturverzeichnis mit Datei
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{figure}[htb]
\centering
\begin{tikzpicture}
\pgfplotsset{/pgf/number format/.cd, fixed, assume math mode}
\pgfkeys{/pgf/number format/use comma}
\pgfmathsetlengthmacro\balkenbreite{20mm}
\definecolor{ha}{HTML}{75C36C}
\definecolor{ton}{HTML}{F78181}
\pgfplotstableread[col sep=comma]{
x, yton, yha
1 , 555 , 0
1 , 0 , 55
2 , 500 , 0
2 , 0 , 70
}\data
\begin{axis}[
width=5cm,
height=5cm,
axis x line*=bottom,
axis y line=left,
ybar,
nodes near coords,
xtick={data},
x tick label style={rotate=90},
xticklabels={X,Z},
xmax=3,
ymin=0,
ymax=600,
ytick={0,100,200,300,400,500},
enlarge x limits=0.25,
legend entries={A, B},
ylabel style={align=center}, ylabel={Test},
ymajorgrids
]
\addplot [fill=ton,bar shift=0.025*\balkenbreite,bar width=0.5*\balkenbreite,font=\footnotesize] table [y=yton] {\data};
\addplot [fill=ha,bar shift=-0.025*\balkenbreite,bar width=0.5*\balkenbreite,font=\footnotesize] table [y=yha] {\data};
\end{axis}
\end{tikzpicture}
\caption{Test2}
\end{figure}
\end{document}[/code]
[/quote]
Die originalen Zahlenwerte sind für die niedrigen Säulen eher gering, sodass sie gar nicht in die Balken passen. Durch die gewählten Beispielzahlen sieht es hier etwas anders aus. Falls es jedoch zu verwirrend sein sollte, dann würde ich ggf. mit Farben arbeiten, um den Unterschied deutlich zu machen.