Quartalszahlen in LaTeX darstellen

Tabellen und Grafiken erstellen und anordnen


Philipp_aus_BP

Quartalszahlen in LaTeX darstellen

Beitrag von Philipp_aus_BP »

Hallo,

ich möchte Quartalszahlen in Latex darstellen. In Excel geht das alles ganz einfach, jedoch bin ich zu blöd dafür das in Latex umzusetzen. Es geht mir vor allem um die Einheiten der X-Achse. So soll das ganze aussehen:
Bild

Bislang sieht mein LaTeX-Code wie folgt aus:

\begin{figure}[H]
\centering
\begin{tikzpicture}
\begin{axis}
\addplot[smooth ,mark=*, blue] coordinates {
(1 , 1131) (2 , 763) (3 , 958) (4 , 1737) (5 , 915)};
\end{axis}
\end{tikzpicture}
\caption{Quartalszahlen (Eigene Darstellung)}
\label{ABB:Quartalszahlen}
\end{figure}

Ich hätte nun einfach gerne das da nicht 1,2,3,4,5 etc auf der X-Achse steht, sondern die Darstellung im Idealfall so ist wie bei der angehängten Grafik. Also Q1 bis Q4 nebeneinander und darunter nochmal das jeweilige Jahr. Ich danke vielmals für Ihre und Eure Hilfe.

Mit freundlichen Grüßen

Philipp


Bartman
Forum-Meister
Forum-Meister
Beiträge: 2456
Registriert: Do 16. Jul 2009, 21:41
Wohnort: Hessische Provinz

Beitrag von Bartman »

Deine Abbildung:

Bild

Mein Vorschlag:
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}

\newcounter{groupcount}
\pgfplotsset{
	compat=newest,% Lesetipp: http://texwelt.de/wissen/fragen/19163
	/pgf/number format/1000 sep=\thinspace,% Abschnitt 92.1 Changing display styles in pgfmanual.pdf
	/pgf/number format/min exponent for 1000 sep=4,
    draw group line/.style n args={5}{% Quelle: https://tex.stackexchange.com/questions/71350
        after end axis/.append code={
            \setcounter{groupcount}{0}
            \pgfplotstableforeachcolumnelement{#1}\of\datatable\as\cell{%
                \def\temp{#2}
                \ifx\temp\cell
                    \ifnum\thegroupcount=0
                        \stepcounter{groupcount}
                        \pgfplotstablegetelem{\pgfplotstablerow}{[index]0}\of\datatable
                        \coordinate [yshift=#4] (startgroup) at (axis cs:\pgfplotsretval,0);
                    \else
                        \pgfplotstablegetelem{\pgfplotstablerow}{[index]0}\of\datatable
                        \coordinate [yshift=#4] (endgroup) at (axis cs:\pgfplotsretval,0);
                    \fi
                \else
                    \ifnum\thegroupcount=1
                        \setcounter{groupcount}{0}
                        \draw [
                            shorten >=-#5,
                            shorten <=-#5
                        ] (startgroup) -- node [anchor=north] {#3} (endgroup);
                    \fi
                \fi
            }
            \ifnum\thegroupcount=1
				\setcounter{groupcount}{0}
				\draw [
					shorten >=-#5,
					shorten <=-#5
				] (startgroup) -- node [anchor=north] {#3} (endgroup);
            \fi
        }
    }
}

\pgfplotstableread{
1 1131 2012
2 763  2012
3 958  2012
4 1737 2012
5 915  2013
}\datatable

\begin{document}
\begin{tikzpicture}
\begin{axis}[
	ymin=0,
	ymax=2000,
	ytick={0,500,...,2000},
	ymajorgrids,
	xtick=data,
	xticklabel={
		\pgfmathparse{mod(\tick-1,4)+1}
		Q\pgfmathprintnumber[int trunc]{\pgfmathresult}
	},
	draw group line={[index]2}{2012}{2012}{-3.5ex}{7pt}
]
\addplot[smooth, mark=*, blue] table \datatable;
\end{axis}
\end{tikzpicture}
\end{document}
Dateianhänge
Quartalszahlen_preview.png
Quartalszahlen_preview.png (263.14 KiB) 754 mal betrachtet

Antworten