Seite 1 von 2

Stapeldiagramm pgfplots

Verfasst: Do 17. Jul 2014, 10:32
von jan_lde
Hallo,

nachdem man mich hier auf das wunderbare pgfplots Paket aufmerksam gemacht hat, habe ich noch eine Frage zur Erstellung eines gesatapelten Liniendiagramms. Ich hab mich schonmal durch die Beispiele auf http://pgfplots.sourceforge.net/gallery.html gerollert, aber kein Diagramm gefunden, was dem nahe kommt was ich will. Da ein Bild mehr als 1000 Worte sagt, hab ich euch mal ein Beispiel in den Anhang gepackt. Die Daten dazu pack ich mal in ne Codeumgebung, ich hoffe das ist ok. :-)
1	0.17115	0.55394	0.6971	0.65344	0.0157	0.87929
2	0.64238	0.80191	0.16366	0.01668	0.81783	0.65905
3	0.86885	0.42977	0.07315	0.12626	0.28043	0.12131
4	0.17057	0.37244	0.36153	0.88735	0.21955	0.76788
5	0.69336	0.64593	0.70009	0.84742	0.53193	0.82532
6	0.24054	0.99533	0.13096	0.47399	0.27708	0.49837
7	0.23183	0.96818	0.48013	0.86949	0.36314	0.3001
8	0.96543	0.54497	0.76546	0.30264	0.5689	0.69436
9	0.67137	0.86029	0.46995	0.72206	0.66963	0.29152
10	0.31333	0.17796	0.75349	0.70197	0.57946	0.62873
11	0.72244	0.09963	0.51003	0.00707	0.01407	0.77102
12	0.98973	0.0555	0.09534	0.7955	0.3129	0.96739
13	0.30684	0.37776	0.38395	0.3854	0.97732	0.74938
14	0.70189	0.90036	0.64864	0.00615	0.00795	0.1469
15	0.56224	0.48462	0.45916	0.16076	0.27302	0.08922
16	0.82157	0.35318	0.4257	0.85515	0.53443	0.56506
17	0.80047	0.48567	0.36371	0.25489	0.14471	0.95966
18	0.6753	0.6737	0.5821	0.44261	0.36274	0.94253
19	0.83784	0.85743	0.66605	0.27026	0.32058	0.53512
20	0.8599	0.41089	0.37954	0.95858	0.83585	0.79425
21	0.70561	0.12291	0.21715	0.69932	0.0365	0.81971
22	0.20045	0.35562	0.80136	0.89809	0.74951	0.07787
23	0.89233	0.31063	0.50437	0.86666	0.52082	0.26937
24	0.74551	0.33981	0.67794	0.92183	0.22209	0.86333
25	0.38234	0.70897	0.84522	0.63723	0.48372	0.36959
26	0.48319	0.47456	0.90873	0.46162	0.65766	0.00159
27	0.83438	0.89913	0.57955	0.4483	0.58212	0.98116
28	0.49274	0.0159	0.93168	0.16264	0.22853	0.85393
29	0.19568	0.13576	0.29019	0.06538	0.21641	0.5337
30	0.6472	0.30968	0.07699	0.73935	0.20007	0.33851
31	0.12317	0.98203	0.75305	0.65892	0.461	0.17464
32	0.31406	0.07436	0.31047	0.53947	0.57473	0.5266
Vielen Dank schonmal und Grüße!

Verfasst: Do 17. Jul 2014, 10:39
von Johannes_B
Gestapelte Liniendiagramme? Anhänge funktionieren hier schon lange nicht mehr, es gibt aber auch eine entsprechende Meldung.
Übrigens kannst du bei TeXwelt problemlos Bilder hochladen ;-)

Das Stichwort heißt »stacked«. Schau mal in Abschnitt 4.5.8. der pgfplots-Doku.
\RequirePackage{filecontents}
\begin{filecontents}{\jobname Data.asc}
1   0.17115   0.55394   0.6971   0.65344   0.0157   0.87929
2   0.64238   0.80191   0.16366   0.01668   0.81783   0.65905
3   0.86885   0.42977   0.07315   0.12626   0.28043   0.12131
4   0.17057   0.37244   0.36153   0.88735   0.21955   0.76788
5   0.69336   0.64593   0.70009   0.84742   0.53193   0.82532
6   0.24054   0.99533   0.13096   0.47399   0.27708   0.49837
7   0.23183   0.96818   0.48013   0.86949   0.36314   0.3001
8   0.96543   0.54497   0.76546   0.30264   0.5689   0.69436
9   0.67137   0.86029   0.46995   0.72206   0.66963   0.29152
10   0.31333   0.17796   0.75349   0.70197   0.57946   0.62873
11   0.72244   0.09963   0.51003   0.00707   0.01407   0.77102
12   0.98973   0.0555   0.09534   0.7955   0.3129   0.96739
13   0.30684   0.37776   0.38395   0.3854   0.97732   0.74938
14   0.70189   0.90036   0.64864   0.00615   0.00795   0.1469
15   0.56224   0.48462   0.45916   0.16076   0.27302   0.08922
16   0.82157   0.35318   0.4257   0.85515   0.53443   0.56506
17   0.80047   0.48567   0.36371   0.25489   0.14471   0.95966
18   0.6753   0.6737   0.5821   0.44261   0.36274   0.94253
19   0.83784   0.85743   0.66605   0.27026   0.32058   0.53512
20   0.8599   0.41089   0.37954   0.95858   0.83585   0.79425
21   0.70561   0.12291   0.21715   0.69932   0.0365   0.81971
22   0.20045   0.35562   0.80136   0.89809   0.74951   0.07787
23   0.89233   0.31063   0.50437   0.86666   0.52082   0.26937
24   0.74551   0.33981   0.67794   0.92183   0.22209   0.86333
25   0.38234   0.70897   0.84522   0.63723   0.48372   0.36959
26   0.48319   0.47456   0.90873   0.46162   0.65766   0.00159
27   0.83438   0.89913   0.57955   0.4483   0.58212   0.98116
28   0.49274   0.0159   0.93168   0.16264   0.22853   0.85393
29   0.19568   0.13576   0.29019   0.06538   0.21641   0.5337
30   0.6472   0.30968   0.07699   0.73935   0.20007   0.33851
31   0.12317   0.98203   0.75305   0.65892   0.461   0.17464
32   0.31406   0.07436   0.31047   0.53947   0.57473   0.5266 
\end{filecontents}
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}%Wir wollen doch aktuell bleiben?
\begin{document}
\begin{tikzpicture}
\begin{axis}[
   title=Inv. cum. normal,
   xlabel={$x$},
   ylabel={$y$},
   ybar stacked,
   bar width=3pt,
]
\addplot table {\jobname Data.asc};
\addplot table [y index=2] {\jobname Data.asc};
\end{axis}
\end{tikzpicture}

\begin{tikzpicture}
\begin{axis}[
   title=Inv. cum. normal,
   xlabel={$x$},
   ylabel={$y$},
   stack plots=y,
]
\addplot table {\jobname Data.asc};
\addplot table [y index=2] {\jobname Data.asc};
\end{axis}
\end{tikzpicture}
\end{document} 

Verfasst: Do 17. Jul 2014, 10:47
von jan_lde
Ja, da hab ich schon geschaut, aber das ist nicht das was ich möchte. Sowas: http://www.directupload.net/file/d/3686 ... ss_png.htm möchte ich.

Ne Meldung hab ich nicht bekommen, oder, und wahrscheinlicher, übersehen. ;-)

Verfasst: Do 17. Jul 2014, 12:24
von jan_lde
Also ich hab was zusammengefummelt. Aber das ist sooooooooo unglaublich hässlich, das muss einfach eleganter gehen. Außerdem funktioniert es nur halb, weil die Abstände nicht stimmen (die bekommt man auch nicht passend) und die y- Achsenbeschriftung nicht mittig ist. Aber vielleicht mal als Disussionsgundlage:
\RequirePackage{filecontents}
\begin{filecontents}{\jobname Data.asc}
1   0.17115   0.55394   0.6971   0.65344   0.0157   0.87929
2   0.64238   0.80191   0.16366   0.01668   0.81783   0.65905
3   0.86885   0.42977   0.07315   0.12626   0.28043   0.12131
4   0.17057   0.37244   0.36153   0.88735   0.21955   0.76788
5   0.69336   0.64593   0.70009   0.84742   0.53193   0.82532
6   0.24054   0.99533   0.13096   0.47399   0.27708   0.49837
7   0.23183   0.96818   0.48013   0.86949   0.36314   0.3001
8   0.96543   0.54497   0.76546   0.30264   0.5689   0.69436
9   0.67137   0.86029   0.46995   0.72206   0.66963   0.29152
10   0.31333   0.17796   0.75349   0.70197   0.57946   0.62873
11   0.72244   0.09963   0.51003   0.00707   0.01407   0.77102
12   0.98973   0.0555   0.09534   0.7955   0.3129   0.96739
13   0.30684   0.37776   0.38395   0.3854   0.97732   0.74938
14   0.70189   0.90036   0.64864   0.00615   0.00795   0.1469
15   0.56224   0.48462   0.45916   0.16076   0.27302   0.08922
16   0.82157   0.35318   0.4257   0.85515   0.53443   0.56506
17   0.80047   0.48567   0.36371   0.25489   0.14471   0.95966
18   0.6753   0.6737   0.5821   0.44261   0.36274   0.94253
19   0.83784   0.85743   0.66605   0.27026   0.32058   0.53512
20   0.8599   0.41089   0.37954   0.95858   0.83585   0.79425
21   0.70561   0.12291   0.21715   0.69932   0.0365   0.81971
22   0.20045   0.35562   0.80136   0.89809   0.74951   0.07787
23   0.89233   0.31063   0.50437   0.86666   0.52082   0.26937
24   0.74551   0.33981   0.67794   0.92183   0.22209   0.86333
25   0.38234   0.70897   0.84522   0.63723   0.48372   0.36959
26   0.48319   0.47456   0.90873   0.46162   0.65766   0.00159
27   0.83438   0.89913   0.57955   0.4483   0.58212   0.98116
28   0.49274   0.0159   0.93168   0.16264   0.22853   0.85393
29   0.19568   0.13576   0.29019   0.06538   0.21641   0.5337
30   0.6472   0.30968   0.07699   0.73935   0.20007   0.33851
31   0.12317   0.98203   0.75305   0.65892   0.461   0.17464
32   0.31406   0.07436   0.31047   0.53947   0.57473   0.5266
\end{filecontents}
\documentclass[10pt,a4paper]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\begin{document}

\begin{tikzpicture}
\begin{semilogyaxis}[
   width=\textwidth,
   height=0.2\textheight,      
   xticklabels=\empty  
   ymode=log,
   ylabel={\textcolor{white}{Laber [Blubb]}}  
]
\addplot table [y index=6] {\jobname Data.asc};
\end{semilogyaxis}
\end{tikzpicture}

\vspace{-10pt}
\begin{tikzpicture}
\begin{semilogyaxis}[
   width=\textwidth,
   height=0.2\textheight,      
   xticklabels=\empty, 
   ymode=log, 
   ylabel={\textcolor{white}{Laber [Blubb]}},
]
\addplot table [y index=5] {\jobname Data.asc};
\end{semilogyaxis}
\end{tikzpicture}

\vspace{-10pt}
\begin{tikzpicture}
\begin{semilogyaxis}[
   width=\textwidth,
   height=0.2\textheight,   
   xticklabels=\empty,
   ylabel={Laber [Blubb]},
]
\addplot table [y index=4] {\jobname Data.asc};
\end{semilogyaxis}
\end{tikzpicture}

\vspace{-10pt}
\begin{tikzpicture}
\begin{semilogyaxis}[
   width=\textwidth,
   height=0.2\textheight,      
   xticklabels=\empty,  
   ymode=log,
   ylabel={\textcolor{white}{Laber [Blubb]}},
]
\addplot table [y index=3] {\jobname Data.asc};
\end{semilogyaxis}
\end{tikzpicture}

\vspace{-10pt}
\begin{tikzpicture}
\begin{semilogyaxis}[
   width=\textwidth,
   height=0.2\textheight,      
   xticklabels=\empty, 
   ymode=log, 
   ylabel={\textcolor{white}{Laber [Blubb]}}, 
]
\addplot table [y index=2] {\jobname Data.asc};
\end{semilogyaxis}
\end{tikzpicture}

\vspace{-10pt}
\begin{tikzpicture}
\begin{semilogyaxis}[
   width=\textwidth,
   height=0.2\textheight,       
   ylabel={\textcolor{white}{Laber [Blubb]}},
   xlabel={mSchr [Zeug]},
]
\addplot table [y index=1] {\jobname Data.asc};
\end{semilogyaxis}
\end{tikzpicture}
\end{document} 

Verfasst: Do 17. Jul 2014, 12:36
von Fundamental
Im Manual für pfgplots gibt es einen ganzen Abschnitt zum gruppieren von Plots (5.7 Grouping plots). Mit der Umgebung groupplot geht das ganze relativ einfach. Achsenbeschriftungen usw müßtest du noch anpassen.

\RequirePackage{filecontents} 
\begin{filecontents}{\jobname Data.asc} 
1   0.17115   0.55394   0.6971   0.65344   0.0157   0.87929 
2   0.64238   0.80191   0.16366   0.01668   0.81783   0.65905 
3   0.86885   0.42977   0.07315   0.12626   0.28043   0.12131 
4   0.17057   0.37244   0.36153   0.88735   0.21955   0.76788 
5   0.69336   0.64593   0.70009   0.84742   0.53193   0.82532 
6   0.24054   0.99533   0.13096   0.47399   0.27708   0.49837 
7   0.23183   0.96818   0.48013   0.86949   0.36314   0.3001 
8   0.96543   0.54497   0.76546   0.30264   0.5689   0.69436 
9   0.67137   0.86029   0.46995   0.72206   0.66963   0.29152 
10   0.31333   0.17796   0.75349   0.70197   0.57946   0.62873 
11   0.72244   0.09963   0.51003   0.00707   0.01407   0.77102 
12   0.98973   0.0555   0.09534   0.7955   0.3129   0.96739 
13   0.30684   0.37776   0.38395   0.3854   0.97732   0.74938 
14   0.70189   0.90036   0.64864   0.00615   0.00795   0.1469 
15   0.56224   0.48462   0.45916   0.16076   0.27302   0.08922 
16   0.82157   0.35318   0.4257   0.85515   0.53443   0.56506 
17   0.80047   0.48567   0.36371   0.25489   0.14471   0.95966 
18   0.6753   0.6737   0.5821   0.44261   0.36274   0.94253 
19   0.83784   0.85743   0.66605   0.27026   0.32058   0.53512 
20   0.8599   0.41089   0.37954   0.95858   0.83585   0.79425 
21   0.70561   0.12291   0.21715   0.69932   0.0365   0.81971 
22   0.20045   0.35562   0.80136   0.89809   0.74951   0.07787 
23   0.89233   0.31063   0.50437   0.86666   0.52082   0.26937 
24   0.74551   0.33981   0.67794   0.92183   0.22209   0.86333 
25   0.38234   0.70897   0.84522   0.63723   0.48372   0.36959 
26   0.48319   0.47456   0.90873   0.46162   0.65766   0.00159 
27   0.83438   0.89913   0.57955   0.4483   0.58212   0.98116 
28   0.49274   0.0159   0.93168   0.16264   0.22853   0.85393 
29   0.19568   0.13576   0.29019   0.06538   0.21641   0.5337 
30   0.6472   0.30968   0.07699   0.73935   0.20007   0.33851 
31   0.12317   0.98203   0.75305   0.65892   0.461   0.17464 
32   0.31406   0.07436   0.31047   0.53947   0.57473   0.5266 
\end{filecontents} 
\documentclass{article} 
\usepackage{pgfplots} 
\usetikzlibrary{pgfplots.groupplots} % Bibliothek für die Umgebung groupplots
\pgfplotsset{compat=1.10}%Wir wollen doch aktuell bleiben? 

\begin{document} 
\begin{tikzpicture} 
\begin{groupplot}[
    group style={
        group name=my plots,
        group size=1 by 5,         % Gruppierung 1x5
        xlabels at=edge bottom,
        xticklabels at=edge bottom,
        vertical sep=0pt
    },
		xlabel={$x$},
		width=8cm,
    height=3cm,
]	
%Plotten der einzelnen Spalten	
\nextgroupplot
\addplot table {\jobname Data.asc}; 
\nextgroupplot
\addplot table [y index=2] {\jobname Data.asc}; 
\nextgroupplot
\addplot table [y index=3] {\jobname Data.asc};
\nextgroupplot 
\addplot table [y index=4] {\jobname Data.asc};
\nextgroupplot 
\addplot table [y index=5] {\jobname Data.asc};
\end{groupplot}
\end{tikzpicture} 
 
\end{document} 

Mit freundlichen Grüßen

Verfasst: Do 17. Jul 2014, 12:49
von Stefan Kottwitz
Johannes_B hat geschrieben:
\pgfplotsset{compat=1.10}%Wir wollen doch aktuell bleiben?
Kleine Anmerkung, das hält nicht aktuell, im Gegenteil. Hat man eine neuere Version von pgfplots installiert, dann wird das auf dem älteren Stand 1.10 übersetzt. Das ist auch gut so, denn es sichert die exakte Darstellung des Dokuments auch in späteren Versionen mit möglicherweise Änderungen, hat nur nicht mit aktuell zu tun. Bei Version 1.10 ist es "neutral", bei früheren Versionen würde man einen Fehler kriegen. Es ist also gar nicht verkehrt, ein gewisses Level zu setzen, mit dem es getestet funktioniert. Es nicht zu setzen, hält aktuell. Dann kann aber auch ein Feature "brechen". Andererseits kann auch ein bug behoben werden und das wirken.
jan_lde hat geschrieben:nachdem man mich hier auf das wunderbare pgfplots Paket aufmerksam gemacht hat
Ich mag das Paket auch sehr! Da kann ich mit wenigen Zeilen tolle mathematische Plots machen. Wenn ich nicht konkret mit Mathe zu tun habe, experimentiere ich selber mit Plots oder baue z.B. im Internet gefundene Mathematica-Plots nach und verbessere sie.

Von meinen Plots poste ich auch viel. Das allerdings auf erwähnter Site TeXwelt.de, dort kann man Bilder einbinden und es gibt eine pgfplots-Kategorie. Von den bereits früher von jemandem verlinkten Bildbeispielen sind viele schöne von mir. :D (Hier im Forum sehe ich halt keine Bilder und finde nix klassifiziert wieder, daher gebe ich mir auch nicht so viel Mühe.)

Stefan

Verfasst: Do 17. Jul 2014, 14:29
von jan_lde
Vielen dank, das sieht ja schon toll aus. Nur fehlt nur noch, dass es nur eine y-Achsenbeschriftung gibt, das hab ich mit
ylabels at=edge left

versucht, das funtioniert abe nicht, da steht trozdem an jeder Achse der Name dran.

@Stefan: Die Bildbeispiele hatte ich mir schon angeschaut, aber für mein Problem war nichts dabei.

Komisch das ich das in der Doku nicht selber gefunden hab. :oops:

Verfasst: Do 17. Jul 2014, 14:41
von Stefan Kottwitz
jan_lde hat geschrieben:@Stefan: Die Bildbeispiele hatte ich mir schon angeschaut, aber für mein Problem war nichts dabei.
Ja, sonst hätte ich direkt verlinkt. Sollte mehr Motivation sein, dass sich da viel mit Plots beschäftigt wird, Deine Fragen daher auch dort sehr willkommen sind, um das Plot-Archiv zu vergrößern. Poste dort gern eine challenge. ;-) Die dort entstandenen Plots stelle ich dann auch auf http://pgfplots.net in die Galerie ein. Spaß an LaTeX und Freude mit Grafiken sind Motivation auf TeXwelt, pgfplots.net, texample.net und des gestarteten Blogs TikZ.de.

Stefan

Verfasst: Do 17. Jul 2014, 15:03
von jan_lde
Dann werde ich das Problem mit der Achsenbeschriftung dort nochmal einstellen, ich mach sowas nur nicht gerne, weil man sich mit Doppelposts ja eher selten beliebt macht.

Verfasst: Do 17. Jul 2014, 15:20
von Johannes_B
Auf TeXwelt wächst mit jeder Frage das Archiv ein kleines Stück mehr. Die Inhalte sind nach Themen sortiert, Antworten (mit Hilfe des Punktesystems/Upvote-systems) peer-reviewed (mir fällt gerade nichts entsprechendes deutsches ein).

Hier auf GoLaTeX sind Doppel- und Crossposts eigentlich untersagt, aber solange du einen entsprechenden Link setzt ist das kein Problem.