von olko » Mo 2. Feb 2026, 14:58
Ich habe bei dem folgenden Diagramm das Problem, dass links und rechts Nullen auftauchen. Mir ist auch klar wieso. Lasse ich die Dummies weg, dann sind die Balken abgeschnitten oder die Beschriftung ist verrutscht. Ich hoffe, dass jemand eine Lösung hat.
\begin{center}
\begin{tikzpicture}
\begin{axis}[
title={Notenverteilung in einer Klasse},
ybar,
bar width=15pt,
ymin=0,
ymax=10,
width=13cm,
height=6cm,
symbolic x coords={Xleft, A, B, C, D, E, F, Xright},
xtick=data,
xticklabels={, A, B, C, D, E, F, }, % Dummy-Beschriftungen leer
ylabel={Anzahl},
axis lines=left,
grid=major,
major grid style={gray!30},
nodes near coords,
every node near coord/.append style={
font=\small,
color=blue
},
% Nullen weiß färben – Trick!
every node near coord/.append style={
/pgfplots/point meta post/.code={
\pgfmathparse{\pgfplotspointmeta==0 ? "white" : "blue"}
\edef\tempcolor{\pgfmathresult}
\tikzset{every node near coord/.style={font=\small, color=\tempcolor}}
}
}
]
\addplot+[
draw=blue!80!black,
fill=blue!30
] coordinates {
(Xleft,0) (A,2) (B,5) (C,9) (D,7) (E,3) (F,1) (Xright,0)
};
\end{axis}
\end{tikzpicture}
\end{center}
Ich habe bei dem folgenden Diagramm das Problem, dass links und rechts Nullen auftauchen. Mir ist auch klar wieso. Lasse ich die Dummies weg, dann sind die Balken abgeschnitten oder die Beschriftung ist verrutscht. Ich hoffe, dass jemand eine Lösung hat.
[code]\begin{center}
\begin{tikzpicture}
\begin{axis}[
title={Notenverteilung in einer Klasse},
ybar,
bar width=15pt,
ymin=0,
ymax=10,
width=13cm,
height=6cm,
symbolic x coords={Xleft, A, B, C, D, E, F, Xright},
xtick=data,
xticklabels={, A, B, C, D, E, F, }, % Dummy-Beschriftungen leer
ylabel={Anzahl},
axis lines=left,
grid=major,
major grid style={gray!30},
nodes near coords,
every node near coord/.append style={
font=\small,
color=blue
},
% Nullen weiß färben – Trick!
every node near coord/.append style={
/pgfplots/point meta post/.code={
\pgfmathparse{\pgfplotspointmeta==0 ? "white" : "blue"}
\edef\tempcolor{\pgfmathresult}
\tikzset{every node near coord/.style={font=\small, color=\tempcolor}}
}
}
]
\addplot+[
draw=blue!80!black,
fill=blue!30
] coordinates {
(Xleft,0) (A,2) (B,5) (C,9) (D,7) (E,3) (F,1) (Xright,0)
};
\end{axis}
\end{tikzpicture}
\end{center}[/code]