Seite 1 von 1

Senkrechte linien über mehrere graphen/plots

Verfasst: Do 11. Apr 2019, 14:46
von herrmann_wst
Hallo zusammen,
ich bin latex Anfänger und versuche nun schon seit längerem senkrechte linien über mehrere Graphen hinweg zu zeichenen, bisher leider ohne Erfolg. Das Bild zeigt grob was ich vor habe. Hier mein Code dazu:
\pgfplotsset{width=13cm, height=3cm}

\begin{figure}
  \centering
	\begin{tikzpicture}[
  		declare function={
    		func(\x)= (\x < 2) * (0) + and(\x >= 2, \x < 3) * (1) + and(\x >= 3, \x < 5) * (0) + and(\x >= 5, \x < 6) * (1) + (\x >= 6) * (0);
  			}
		]
	\begin{axis}[
  	axis x line=middle, axis y line=middle,
  	y label style={at={(axis description cs:-0.04,.5)},anchor=south},
  	ymin=0, ymax=1, ytick={0,0}, ylabel=$u(t)$,
  	xmin=0, xmax=6.5, xtick={0,0}, xlabel=$t$,
  	domain=0:6.3,samples=201, 
	]

	\addplot [blue,thick] {func(x)};
	\end{axis}
	\end{tikzpicture} 

\ \\
\ \\

\begin{tikzpicture}[
  	declare function={
    	func(\x)= (\x < 2) * (0) + and(\x >= 2, \x < 3) * (sin(\x * 57.2958 * pi * 2 * 2)) + and(\x >= 3, \x < 5) * (0) + and(\x >= 5, \x < 6) * (sin(\x * 57.2958 * pi * 4)) + (\x >= 6) * 0;
  		}
	]

	\begin{axis}[
  	axis x line=middle, axis y line=middle,
  y label style={at={(axis description cs:-0.04,.5)},anchor=south},
  	ymin=-1, ymax=1, ytick={0,0}, ylabel=$u(t)$,
  	xmin=0, xmax=6.5, xtick={0,0}, xlabel=$t$,
  	domain=0:6.3,samples=201, 
	]

	\addplot [blue,thick] {func(x)};
	\end{axis}
	\end{tikzpicture} 
	
	
\ \\
\ \\	
	
	
\begin{tikzpicture}[
  		declare function={
   			func(\x)= (\x < 2) * (sin(\x * 57.2958 * pi * 2)) + and(\x >= 2, \x < 3) * (sin(\x * 57.2958 * pi * 2 * 2)) + and(\x >= 3, \x < 5) * (sin(\x * 57.2958 * pi * 2)) + and(\x >= 5, \x < 6) * (sin(\x * 57.2958 * pi * 4)) + (\x >= 6) * (sin(\x * 57.2958 * pi * 2));
  		}
]

\begin{axis}[
  axis x line=middle, axis y line=middle,
  y label style={at={(axis description cs:-0.04,.5)},anchor=south},
  ymin=-1, ymax=1, ytick={0,0}, ylabel=$u(t)$,
  xmin=0, xmax=6.5, xtick={0,0}, xlabel=$t$,
  domain=0:6.3,samples=201, 
]

\addplot [blue,thick] {func(x)};
\end{axis}
\end{tikzpicture} 

\ \\
\ \\	
	
	
\begin{tikzpicture}[
  		declare function={
   			func(\x)= (\x < 2) * (sin(\x * 57.2958 * pi * 2)) + and(\x >= 2, \x < 3) * (sin(\x * 57.2958 * pi * 2 + 180)) + and(\x >= 3, \x < 5) * (sin(\x * 57.2958 * pi * 2)) + and(\x >= 5, \x < 6) * (sin(\x * 57.2958 * pi * 2 + 180)) + (\x >= 6) * (sin(\x * 57.2958 * pi * 2));
  		}
]

\begin{axis}[
  axis x line=middle, axis y line=middle,
  y label style={at={(axis description cs:-0.04,.5)},anchor=south},
  ymin=-1, ymax=1, ytick={0,0}, ylabel=$u(t)$,
  xmin=0, xmax=6.5, xtick={0,0}, xlabel=$t$,
  domain=0:6.3,samples=201, 
]

\addplot [blue,thick] {func(x)};
\end{axis}
\end{tikzpicture} 

\ \\
\ \\	
	
	
\begin{tikzpicture}[
  		declare function={
   			func(\x)= (\x < 2.5) * (sin(\x * 57.2958 * pi * 2)) + and(\x >= 2.5, \x < 5.5) * (sin(\x * 57.2958 * pi * 2 + 180)) + (\x >= 5.5) * (sin(\x * 57.2958 * pi * 2));
  		}
]

\begin{axis}[
  axis x line=middle, axis y line=middle,
  y label style={at={(axis description cs:-0.04,.5)},anchor=south},
  ymin=-1, ymax=1, ytick={0,0}, ylabel=$u(t)$,
  xmin=0, xmax=6.5, xtick={0,0}, xlabel=$t$,
  domain=0:6.3,samples=201, 
]

\addplot [blue,thick] {func(x)};
\end{axis}
\end{tikzpicture} 
	
\caption{Datensignal mit ASK, FSK, PSK und differnziell PSK moduliertem Signal}\label{fig:modulation}
\end{figure}

ist nicht unbedingt schön, aber tut größtenteils was es soll :)

Die Frage ist nun nur noch: wie bekomme ich die linien da rein?

MfG

Philipp

Verfasst: Do 11. Apr 2019, 19:37
von Bartman
Bild

Vervollständige Dein unvollständiges Beispiel und sieh Dir bei der Gelegenheit den Abschnitt 5.8 Grouping plots in der Dokumentation von pgfplots an.

Du darfst Deine Funktionen der Option /tikz/declare function der groupplot-Umgebung zuweisen.

Du musst die Optionen nicht bei jedem \addplot-Befehl erneut angeben, sondern darfst diese in der Optionenliste der erwähnten Umgebung wie folgt zusammenfassen:
no markers,
every axis plot/.append style={blue, thick},
Beachte die Option compat, wenn sie noch nicht in Deiner Präambel vorkommen sollte.

Ein Beispiel:
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots} 

\pgfplotsset{
    compat=newest%, aktuell 1.16
}
 
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[
    group style={group size=1 by 6},
    width=13cm, height=3cm,
    axis lines=middle,
    y label style={anchor=north east},
    ymin=-1, ymax=1, ytick=\empty, ylabel=$u(t)$,
    xmin=0, xmax=6.5, xtick=\empty, xlabel=$t$,
    domain=0:6.3,samples=201,
    no markers,
    every axis plot/.append style={blue, thick},
    /tikz/declare function = {
        f1(\x)=(\x < 2) * (0) + and(\x >= 2, \x < 3) * (1) + 
            and(\x >= 3, \x < 5) * (0) + 
            and(\x >= 5, \x < 6) * (1) + (\x >= 6) * (0);
        f2(\x)=(\x < 2) * (0) + and(\x >= 2, \x < 3) 
            * (sin(\x * 57.2958 * pi * 2 * 2)) + 
            and(\x >= 3, \x < 5) * (0) + and(\x >= 5, \x < 6) 
            * (sin(\x * 57.2958 * pi * 4)) + (\x >= 6) * 0;
        f3(\x)=(\x < 2) * (sin(\x * 57.2958 * pi * 2)) + 
            and(\x >= 2, \x < 3) * (sin(\x * 57.2958 * pi * 2 * 2)) + 
            and(\x >= 3, \x < 5) * (sin(\x * 57.2958 * pi * 2)) + 
            and(\x >= 5, \x < 6) * (sin(\x * 57.2958 * pi * 4)) + (\x >= 6) 
            * (sin(\x * 57.2958 * pi * 2));
        f4(\x)=(\x < 2) * (sin(\x * 57.2958 * pi * 2)) + 
            and(\x >= 2, \x < 3) * (sin(\x * 57.2958 * pi * 2 + 180)) + 
            and(\x >= 3, \x < 5) * (sin(\x * 57.2958 * pi * 2)) + 
            and(\x >= 5, \x < 6) * (sin(\x * 57.2958 * pi * 2 + 180)) + (\x >= 6) 
            * (sin(\x * 57.2958 * pi * 2));
        f5(\x)=(\x < 2.5) * (sin(\x * 57.2958 * pi * 2)) + 
            and(\x >= 2.5, \x < 5.5) * (sin(\x * 57.2958 * pi * 2 + 180)) 
            + (\x >= 5.5) * (sin(\x * 57.2958 * pi * 2));
    }
]  
\nextgroupplot[ymin=0]
\addplot {f1(x)};
\pgfplotsinvokeforeach{1,...,6}{
    \coordinate (#1-top) at (#1,1.3);
}
\nextgroupplot
\addplot {f2(x)};
\nextgroupplot
\addplot {f3(x)};
\nextgroupplot
\addplot {f4(x)};
\nextgroupplot
\addplot {f5(x)};
\pgfplotsinvokeforeach{1,...,6}{
    \coordinate (#1-bottom) at (#1,-1.5);
}
\end{groupplot}
\foreach \x in {1,...,6}{
    \draw [red, dashed, thick] (\x-top) -- (\x-bottom);
}
\end{tikzpicture}
\end{document}

Verfasst: Fr 12. Apr 2019, 11:11
von herrmann_wst
Hi,

funktioniert. Danke :D
Vervollständige Dein unvollständiges Beispiel
Ups, hab ich vergessen, hab das in der eile einfach nur raus kopiert, sorry.