Seite 1 von 1

Balkendiagramm mit 'schwebenden Balken'

Verfasst: Mo 11. Jun 2018, 11:40
von najaemely
Hallo zusammen,

ich sitze bereits seit einigen Stunden an einem doch recht simpel erscheinenden Problem. Ich habe ein Balkendiagramm erstellt (wie schon viele zuvor), jedoch beginnt die 0-Linie der Y-Koordinate nicht am unteren Rand des Diagramms. Dadurch 'schweben' die Balken. Bei anderen Diagrammen, die ich genauso aufgebaut habe, ist mir das nicht passiert. Kann mir einer erklären woran das liegt? Und wie ich das Problem lösen kann?

Hier das Beispiel:

\documentclass[a4paper,12pt]{book}
\usepackage{pgfplots}

\begin{document}

\begin{figure}
\begin{center}
\begin{tikzpicture}
\begin{axis}[
ybar,
enlargelimits=0.15,
ylabel={Prozent},
symbolic x coords={20-24,25-29,30-34,35-39,>39},
xtick=data,
x tick label style={rotate=45,anchor=east},
]
\addplot [black,fill=blue!30]
coordinates {(20-24,4.4)(25-29,46.7)(30-34,31.1)(35-39,15.6)(>39,2.2)};
\addplot [black,fill=red!30]
coordinates {(20-24,5.6) (25-29,50)(30-34,33.3)(35-39,5.6)(>39,0)};
\end{axis}
\end{tikzpicture}
\caption{Altersverteilung konsekutiver Studiengang}
\end{center}
\end{figure}

\end{document}

Verfasst: Mo 11. Jun 2018, 12:52
von markusv
Hallo.

Begrenze enlargelimits auf die x-Achse und setze ymin=0:
\documentclass[a4paper,12pt]{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{pgfplots} 
\pgfplotsset{compat=newest}
\usepackage{mathtools}


 \begin{document} 
 \begin{figure} 
 \begin{center} 
 \begin{tikzpicture} 
 \begin{axis}[ 
 ybar, 
 enlarge x limits=0.15, %geändert
 ylabel={Prozent}, 
 symbolic x coords={20-24,25-29,30-34,35-39,>39}, 
 xtick=data, ymin=0, %ymin hinzugefügt
 x tick label style={rotate=45,anchor=east}, 
 ] 
 \addplot [black,fill=blue!30] 
 coordinates {(20-24,4.4)(25-29,46.7)(30-34,31.1)(35-39,15.6)(>39,2.2)}; 
 \addplot [black,fill=red!30] 
 coordinates {(20-24,5.6) (25-29,50)(30-34,33.3)(35-39,5.6)(>39,0)};
 \end{axis} 
 \end{tikzpicture} 
 \caption{Altersverteilung konsekutiver Studiengang} 
 \end{center} 
 \end{figure} 
 \end{document} 
EDIT: mit fontenc funktioniert es natürlich auch außerhalb des Mathematik-Modus.

Verfasst: Mo 11. Jun 2018, 13:23
von najaemely
Wunderbar! Vielen Dank!

Verfasst: Mo 11. Jun 2018, 13:37
von Bartman
Nutze für Deinen nächsten Beitrag die Eigenschaften des Editors des Forums.

Meines Erachtens passen da Gedankenstriche besser, als Bindestriche.
\documentclass[a4paper,12pt]{book}
\usepackage{selinput}% https://texwelt.de/wissen/fragen/5546
\SelectInputMappings{
	adieresis={ä},
	germandbls={ß}
}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[ngerman]{babel}
\usepackage{pgfplots} 

\pgfplotsset{compat=newest}% https://texwelt.de/wissen/fragen/19163

\begin{document} 
\begin{figure} 
	\centering% https://texwelt.de/wissen/fragen/1033
	\begin{tikzpicture} 
	\begin{axis}[ 
		ybar, 
		enlarge x limits=0.15,
		ylabel={Prozent}, 
		symbolic x coords={20--24,25--29,30--34,35--39,>39}, 
		xtick=data, 
		ymin=0,
		x tick label style={rotate=45,anchor=east}, 
	] 
	\addplot [fill=blue!30] 
		coordinates {(20--24,4.4)(25--29,46.7)(30--34,31.1)(35--39,15.6)(>39,2.2)}; 
	\addplot [fill=red!30] 
		coordinates {(20--24,5.6) (25--29,50)(30--34,33.3)(35--39,5.6)(>39,0)};
	\end{axis} 
	\end{tikzpicture} 
	\caption{Altersverteilung konsekutiver Studiengang}
\end{figure} 
\end{document}