von cis » Di 4. Aug 2020, 22:39
Da der Startpost ellenlang beschreibt, aber kein kurzes Minimalbeispiel angibt, insb. keine exemplarische Tabelle mit Eingangsdaten, ist der Helfer weitgehend auf persönliche Spekulation angewiesen, was da was sein soll und wie sein soll und was wo drannstehen soll.
Als stacked plot lässt sich das auch umsetzen; allerdings wird man diese spezielle Gestalt m.E. nicht ohne entsprechende Manipulationen erreichen.
- 5555555.png (8.43 KiB) 3620 mal betrachtet
%\documentclass[a4paper,12pt]{article}
\documentclass[margin=5pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
% Farben definieren
% https://html-color-codes.info/colors-from-image/
\definecolor{myorange}{HTML}{ED7D31}
\definecolor{myyellow}{HTML}{FFC000}
\definecolor{myblue}{HTML}{4472C4}
\colorlet{myaxisblue}{myblue!60}{}
% BarWidth
\pgfmathsetlengthmacro\BarWidth{7mm}
% Diagrammdaten
\pgfplotstableread[col sep=comma]{
x, yBlau, yGelb, yOrange
1, 2.7, 0, 2.5
2, 2.7, 1.8, 0
4, 2.5, 0, 3.6
5, 2.5, 1.6, 0
}\data
%
\pgfplotstablegetelem{0}{yBlau}\of{\data}
\pgfmathsetmacro\BlueSumI{2*\pgfplotsretval}
%
\pgfplotstablegetelem{3}{yBlau}\of{\data}
\pgfmathsetmacro\BlueSumII{2*\pgfplotsretval}
\begin{document}
%Test: \BlueSumI, %\BlueSumII
\pgfplotsset{/pgf/number format/.cd, fixed, assume math mode}% seri-
\begin{tikzpicture}[font=\footnotesize\sffamily]% fenlos
\begin{axis}[
ybar stacked,
bar shift=0pt,
bar width=\BarWidth,
x=\BarWidth,
xtick=data,
xtick={1.5, 4.5},
xticklabels={I, II},
ytick={1,...,6},
every axis plot/.append style={draw=none},
ymin=0,
xmin=0, xmax=7,
axis lines=middle,
axis line style = {-latex, draw=myaxisblue},
every tick/.style={draw=myaxisblue},
enlarge y limits={abs=0.5, upper},
nodes near coords,
]
\addplot[fill=myblue,
nodes near coords={ %\coordindex
\pgfmathparse{\coordindex==1 || \coordindex== 3 ? "" : (\coordindex==0 ? \BlueSumI : \BlueSumII)}\pgfmathresult
},
nodes near coords style={xshift=0.5*\BarWidth},
] table [y=yBlau] {\data};
\addplot[fill=myorange] table [y=yOrange] {\data};
\addplot[fill=myyellow] table [y=yGelb] {\data};
\end{axis}
\end{tikzpicture}
\end{document}
PS: So, wie ich es glaube, rausgehört zu haben sollen die nodes near coords die Diagrammdaten wiedergeben.
Zoid hat geschrieben: ↑Di 4. Aug 2020, 18:32
Mir gefällt dabei die Angabe der jeweiligen Werte für die y-Achse in den jeweiligen Säulen. Wenn man die später als Summe noch über die Säulen platzieren könnte, wäre das super. ....
Wenn bei den blauen Balken die Summe von eigentlich zwei Balken steht, machen aber m.E. die Werte auf der y-Achse keinen besonderen Sinn mehr.
PPS: Gut, also genug investiert. Das obige MWE sollte alles Nötige enthalten.
Da der Startpost ellenlang beschreibt, aber kein kurzes Minimalbeispiel angibt, insb. keine exemplarische Tabelle mit Eingangsdaten, ist der Helfer weitgehend auf persönliche Spekulation angewiesen, was da was sein soll und wie sein soll und was wo drannstehen soll.
Als [tt]stacked plot[/tt] lässt sich das auch umsetzen; allerdings wird man diese spezielle Gestalt m.E. nicht ohne entsprechende Manipulationen erreichen.
[attachment=0]5555555.png[/attachment]
[code]
%\documentclass[a4paper,12pt]{article}
\documentclass[margin=5pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
% Farben definieren
% https://html-color-codes.info/colors-from-image/
\definecolor{myorange}{HTML}{ED7D31}
\definecolor{myyellow}{HTML}{FFC000}
\definecolor{myblue}{HTML}{4472C4}
\colorlet{myaxisblue}{myblue!60}{}
% BarWidth
\pgfmathsetlengthmacro\BarWidth{7mm}
% Diagrammdaten
\pgfplotstableread[col sep=comma]{
x, yBlau, yGelb, yOrange
1, 2.7, 0, 2.5
2, 2.7, 1.8, 0
4, 2.5, 0, 3.6
5, 2.5, 1.6, 0
}\data
%
\pgfplotstablegetelem{0}{yBlau}\of{\data}
\pgfmathsetmacro\BlueSumI{2*\pgfplotsretval}
%
\pgfplotstablegetelem{3}{yBlau}\of{\data}
\pgfmathsetmacro\BlueSumII{2*\pgfplotsretval}
\begin{document}
%Test: \BlueSumI, %\BlueSumII
\pgfplotsset{/pgf/number format/.cd, fixed, assume math mode}% seri-
\begin{tikzpicture}[font=\footnotesize\sffamily]% fenlos
\begin{axis}[
ybar stacked,
bar shift=0pt,
bar width=\BarWidth,
x=\BarWidth,
xtick=data,
xtick={1.5, 4.5},
xticklabels={I, II},
ytick={1,...,6},
every axis plot/.append style={draw=none},
ymin=0,
xmin=0, xmax=7,
axis lines=middle,
axis line style = {-latex, draw=myaxisblue},
every tick/.style={draw=myaxisblue},
enlarge y limits={abs=0.5, upper},
nodes near coords,
]
\addplot[fill=myblue,
nodes near coords={ %\coordindex
\pgfmathparse{\coordindex==1 || \coordindex== 3 ? "" : (\coordindex==0 ? \BlueSumI : \BlueSumII)}\pgfmathresult
},
nodes near coords style={xshift=0.5*\BarWidth},
] table [y=yBlau] {\data};
\addplot[fill=myorange] table [y=yOrange] {\data};
\addplot[fill=myyellow] table [y=yGelb] {\data};
\end{axis}
\end{tikzpicture}
\end{document}
[/code]
PS: So, wie ich es glaube, rausgehört zu haben sollen die nodes near coords die Diagrammdaten wiedergeben.
[quote=Zoid post_id=112244 time=1596558733 user_id=8828]
Mir gefällt dabei die Angabe der jeweiligen Werte für die y-Achse in den jeweiligen Säulen. Wenn man die später als Summe noch über die Säulen platzieren könnte, wäre das super. ....
[/quote]
[i]Wenn bei den blauen Balken die Summe von eigentlich zwei Balken steht, machen aber m.E. die Werte auf der y-Achse keinen besonderen Sinn mehr.[/i]
PPS: Gut, also genug investiert. Das obige MWE sollte alles Nötige enthalten.