Seite 1 von 1

TikZ/pgfPlot x-Achse mit Text beschriften?

Verfasst: Di 16. Feb 2016, 20:59
von StefanB
Hallo,

ich möchte folgendes Balkendiagramm auf der x-Achse mit Text beschriften.
Also da wo jetzt 0 steht, sollte z.B. Aufgabe 1 stehen, bei 1 Umrechnung, bei 2...usw.

Ist das irgendwie möglich?

Hier mein Bsp.:
\documentclass[10pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
height=6cm,
width=\textwidth-0.5cm,
enlargelimits=0.02,
legend style={
	at={(0.5,-0.2)},
	anchor=north,
	legend columns=-1
},
ymin=0,
ymax=100,
x tick label style={/pgf/number format/1000 sep=},
x tick label style={rotate=45,anchor=east},
ylabel={richtige Antworten in \%},
ybar interval=0.7,
ytick={0,10,...,100}
]
\addplot coordinates {
	(0,43.6782)
	(1,65.4321)
	(2,79.7468)
	(3,84.6154)
	(4,66.6667)
	(5,61.6438)
	(6,33.2)
};
\addplot coordinates {
	(0,65.4378)
	(1,83.0128)
	(2,87.785)
	(3,91.3333)
	(4,81.407)
	(5,80.2448)
	(6,33.2)
	
};
\addplot coordinates {
	(0,56.25)
	(1,73.0769)
	(2,62.069)
	(3,74.0741)
	(4,79.1667)
	(5,54.1667)
	(6,33.2)
};
\addplot coordinates {
	(0,70.5584)
	(1,82.2581)
	(2,70)
	(3,88.9503)
	(4,77.6536)
	(5,79.0698)
	(6,33.2)
	
};
\legend{Stichprobe  1,Stichprobe 2,Stichprobe 3, Stichprobe 4}
\end{axis}
\begin{axis}[
height=6cm,
width=\textwidth-0.5cm,
enlargelimits=0.02,
ymin=0,
ymax=100,
ytick={0,10,...,100},
hide x axis,
axis y line*=right,
]
\addplot[opacity=0]{100};
\end{axis}
\end{tikzpicture} 
\end{document}

Verfasst: Di 16. Feb 2016, 21:44
von Bartman
Sieh Dir das obere Beispiel auf Seite 82 der Dokumentation von tikz oder meinen Beitrag zu einem ähnlichen Balkendiagramm an.

Verfasst: Di 16. Feb 2016, 22:13
von esdd
Bartman meint vermutlich die Dokumentation zu [d]pgfplots[/d]. Bei der derzeitigen Version 1.13 käme dann auch eher das Beispiel auf Seite 84 unten in Frage.

Falls Du nur die Beschriftung nicht aber die Koordinatenangaben bei den einzelnen Plots ändern möchtest, dann wäre eine weitere Möglichkeit
\documentclass[10pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
%\usepackage{graphicx}% wird von pgfplots mit geladen
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
height=6cm,
width=\textwidth-0.5cm,
enlargelimits=0.02,
legend style={
   at={(xticklabel cs:.5)},% Legende unterhalb der Ticklabels
   anchor=north,
   legend columns=-1
},
ymin=0,
ymax=100,
%x tick label style={/pgf/number format/1000 sep=},% wird das benötigt?
x tick label style={rotate=45,anchor=east},
xtick={0,...,6},% Ticks
xticklabels={text1, text2, text3, text4, text5, langer text6},% zugehörige Beschriftungen
ylabel={richtige Antworten in \%},
ybar interval=0.7,
ytick={0,10,...,100}
]
\addplot coordinates {
   (0,43.6782)
   (1,65.4321)
   (2,79.7468)
   (3,84.6154)
   (4,66.6667)
   (5,61.6438)
   (6,33.2)
};
\addplot coordinates {
   (0,65.4378)
   (1,83.0128)
   (2,87.785)
   (3,91.3333)
   (4,81.407)
   (5,80.2448)
   (6,33.2)
   
};
\addplot coordinates {
   (0,56.25)
   (1,73.0769)
   (2,62.069)
   (3,74.0741)
   (4,79.1667)
   (5,54.1667)
   (6,33.2)
};
\addplot coordinates {
   (0,70.5584)
   (1,82.2581)
   (2,70)
   (3,88.9503)
   (4,77.6536)
   (5,79.0698)
   (6,33.2)
   
};
\legend{Stichprobe  1,Stichprobe 2,Stichprobe 3, Stichprobe 4}
\end{axis}
\begin{axis}[
height=6cm,
width=\textwidth-0.5cm,
enlargelimits=0.02,
ymin=0,
ymax=100,
ytick={0,10,...,100},
hide x axis,
axis y line*=right,
]
\addplot[opacity=0]{100};
\end{axis}
\end{tikzpicture} 
\end{document}

Verfasst: Di 16. Feb 2016, 23:35
von Bartman
esdd hat geschrieben:Bartman meint vermutlich die Dokumentation zu [d]pgfplots[/d]. Bei der derzeitigen Version 1.13 käme dann auch eher das Beispiel auf Seite 84 unten in Frage.
Deine Vermutung ist zutreffend. Danke für die Berichtigung.

Verfasst: Mi 2. Mär 2016, 18:57
von StefanB
Hi,

Entschuldigung, dass ich mich erst jetzt melde, aber genau das habe ich gesucht!