Gemeinsame Legende Tikzpicture - Subfigure Thema ist als GELÖST markiert

Tabellen und Grafiken erstellen und anordnen


MenschMax

Gemeinsame Legende Tikzpicture - Subfigure

Beitrag von MenschMax »

Hallo,

ich kriege es leider nicht hin, für meine beiden Grafiken eine gemeinsame Legende einzufügen. Die beiden Grafiken sollen nebeneinander stehen und lediglich "CFD" und "Messung" stehen haben, also nicht doppelt.

a) Hat mir jemand eine Idee bzw. Anregung?

b) Gibt es sonst noch Gestaltungshinweise zu den beiden Grafiken? Lässt man prinzipiell vielleicht die Beschriftung der Achsen wegfallen in einem Diagramm wenn man zwei mal nebeneinander die selbe Art von Diagramm hat, oder passt das so allgemein?

Danke Ihr lieben Menschen
\documentclass[a4paper,12pt,twoside]{report} 

\usepackage[T1]{fontenc} 
\usepackage[ngerman]{babel} 
\usepackage{lmodern} 
\usepackage{tikz} 
\usepackage{subfigure}
\usepackage{pgfplots, pgfplotstable}

\begin{document}
Dies ist ein Test
 \begin{figure}[htb] 
 \centering 
 \subfigure[SD Links]{
 \begin{tikzpicture} 
 \begin{axis}[ 
  height=6cm, 
 legend style={ 
 at={(0.5,-0.3)}, 
 anchor=north, 
 legend columns=-1 
 }, 
 ymin=0, 
 ymax=90,
 xmin=0, 
 xtick={20,40,60,80,100}, 
 ylabel={Temperatur in °C}, 
 ymajorgrids, 
 nodes near coords, 
 every node near coord/.append style={font=\footnotesize}, 
 point meta=explicit symbolic, 
 ]
 \addplot coordinates { 
 (0,4.499674202) 
 (10,4.324053491)
 (20,10.4473975) 
 (30,19.59755699) 
 (40,29.29712891)
 (50,41.1387128)
 (60,50.13531996)
 (70,52.05104588)
 (80,57.3142446)
 (90,67.88965727)
 (100,82.47613206)
  }; 
	\addplot coordinates { 
 (0,6.91) 
 (10,7.75)
 (20,15.90) 
 (30,23.64) 
 (40,31.74)
 (50,43.52)
 (60,51.28)
 (70,53.51)
 (80,56.41)
 (90,63.08)
 (100,73.72)
  }; 
 \legend{CFD,Messung} 
 \end{axis} 
 \end{tikzpicture} 
 }
 \subfigure[SD Rechts]{ 
  \begin{tikzpicture} 
 \begin{axis}[ 
 height=6cm, 
 legend style={ 
 at={(0.5,-0.3)}, 
 anchor=north, 
 legend columns=-1 
 }, 
 ymin=0, 
 ymax=90,
 xmin=0, 
 xtick={20,40,60,80,100}, 
 ylabel={Temperatur in °C}, 
 ymajorgrids, 
 nodes near coords, 
 every node near coord/.append style={font=\footnotesize}, 
 point meta=explicit symbolic, 
 ] 
 \addplot coordinates { 
 (0,6.064873943) 
 (10,5.272728089)
 (20,15.6922116) 
 (30,23.23744567) 
 (40,29.58409871)
 (50,40.69421012)
 (60,45.08954257)
 (70,51.30158893)
 (80,53.84531295)
 (90,66.89697259)
 (100,82.52502564)
  }; 
	\addplot coordinates { 
 (0,6.65) 
 (10,8.82)
 (20,16.35) 
 (30,23.90) 
 (40,33.49)
 (50,42.16)
 (60,48.69)
 (70,52.96)
 (80,56.90)
 (90,68.79)
 (100,72.82)
  }; 
 \legend{CFD,Messung} 
 \end{axis} 
 \end{tikzpicture} 
 }
 \caption{Vergleich für verschiedene Netze von}
 \end{figure}


\end{document}

esdd
Forum-Meister
Forum-Meister
Beiträge: 2561
Registriert: So 7. Feb 2010, 16:36

Beitrag von esdd »

subfigure ist obsolet. Ich verwende deshalb hier subcaption. Außerdem sind Deine Diagramme zu groß, um nebeneinander zu passen.

Für die gemeinsame Legende kannst Du einfach bei einem der Plots den \legend Befehl weglassen und bei dem anderen die Option legend to name=<labelname> verwenden. Dann lässt sich die Legende mit \ref{<labelname>} an der gewünschten Stelle einfügen.
\documentclass[a4paper,12pt,twoside]{report} 

\usepackage[T1]{fontenc} 
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel} 
\usepackage{lmodern} 
\usepackage{subcaption} 
\usepackage{pgfplots}% lädt auch tikz
\pgfplotsset{compat=newest}% compat immer setzen!

\usepackage{siunitx}

\begin{document} 
 Dies ist ein Test 
  \begin{figure}[htb] 
  \centering 
  \subcaptionbox{SD Links}{ 
  \begin{tikzpicture} 
  \begin{axis}[ 
   height=5cm, 
  legend style={ 
  at={(0.5,-0.3)}, 
  anchor=north, 
  legend columns=-1 
  }, 
  ymin=0, 
  ymax=90, 
  xmin=0, 
  xtick={20,40,60,80,100}, 
  ylabel={Temperatur in \si{\degreeCelsius}}, 
  ymajorgrids, 
  nodes near coords, 
  every node near coord/.append style={font=\footnotesize}, 
  point meta=explicit symbolic, 
  legend to name={legend:SD}
  ] 
  \addplot coordinates { 
  (0,4.499674202) 
  (10,4.324053491) 
  (20,10.4473975) 
  (30,19.59755699) 
  (40,29.29712891) 
  (50,41.1387128) 
  (60,50.13531996) 
  (70,52.05104588) 
  (80,57.3142446) 
  (90,67.88965727) 
  (100,82.47613206) 
   }; 
    \addplot coordinates { 
  (0,6.91) 
  (10,7.75) 
  (20,15.90) 
  (30,23.64) 
  (40,31.74) 
  (50,43.52) 
  (60,51.28)
  (70,53.51) 
  (80,56.41) 
  (90,63.08) 
  (100,73.72) 
   }; 
  \legend{CFD,Messung} 
  \end{axis} 
  \end{tikzpicture} 
  }\hfill 
  \subcaptionbox{SD Rechts}{ 
   \begin{tikzpicture} 
  \begin{axis}[ 
  height=5cm, 
  legend style={ 
  at={(0.5,-0.3)}, 
  anchor=north, 
  legend columns=-1 
  }, 
  ymin=0, 
  ymax=90, 
  xmin=0, 
  xtick={20,40,60,80,100}, 
  ylabel={Temperatur in \si{\degreeCelsius}}, 
  ymajorgrids, 
  nodes near coords, 
  every node near coord/.append style={font=\footnotesize}, 
  point meta=explicit symbolic, 
  ] 
  \addplot coordinates { 
  (0,6.064873943) 
  (10,5.272728089) 
  (20,15.6922116) 
  (30,23.23744567) 
  (40,29.58409871) 
  (50,40.69421012) 
  (60,45.08954257) 
  (70,51.30158893) 
  (80,53.84531295) 
  (90,66.89697259) 
  (100,82.52502564) 
   }; 
    \addplot coordinates { 
  (0,6.65) 
  (10,8.82) 
  (20,16.35) 
  (30,23.90) 
  (40,33.49) 
  (50,42.16) 
  (60,48.69) 
  (70,52.96) 
  (80,56.90) 
  (90,68.79) 
  (100,72.82) 
   }; 
  %\legend{CFD,Messung} 
  \end{axis} 
  \end{tikzpicture} 
  }\\
  \ref{legend:SD}
  \caption{Vergleich für verschiedene Netze von} 
  \end{figure} 
\end{document} 

MenschMax

Beitrag von MenschMax »

Super das klappt! Wenn Du mir jetzt noch sagen könntest wie ich die Legende unter die richtige Grafik packe dann hab ichs :-) Habe nämlich nun 4 Grafiken eingebunden und muss die Legende unter die zwei oberen packen. Über die Koordinaten lässt sie sich aber nicht mehr steuern?
\documentclass[a4paper,12pt,twoside]{report} 

\usepackage[T1]{fontenc} 
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel} 
\usepackage{lmodern} 
\usepackage{subcaption} 
\usepackage{pgfplots}% lädt auch tikz
\pgfplotsset{compat=newest}% compat immer setzen!

\usepackage{siunitx}

\begin{document} 

\begin{figure}[htb] 
 \centering 
 \subcaptionbox{SD Links}{ 
 \begin{tikzpicture} 
 \begin{axis}[ 
 height=10cm, 
 width=8cm,
 legend style={ 
 at={(0.5,-0.3)}, 
 anchor=north, 
 legend columns=-1 
 }, 
 ymin=0, 
 ymax=90,
 xmin=0, 
 xtick={20,40,60,80,100}, 
 ytick={0,10,20,30,40,50,60,70,80,90}, 
 ylabel={Temperatur in °C}, 
 xlabel={Klappenstellung in \%},
 ymajorgrids,
 xmajorgrids, 
 nodes near coords, 
 every node near coord/.append style={font=\footnotesize}, 
 point meta=explicit symbolic,
 legend to name={legend:SD} 
 ]
 \addplot+[name path=A] coordinates { 
 (0,4.499674202) 
 (10,4.324053491)
 (20,10.4473975) 
 (30,19.59755699) 
 (40,29.29712891)
 (50,41.1387128)
 (60,50.13531996)
 (70,52.05104588)
 (80,57.3142446)
 (90,67.88965727)
 (100,82.47613206)
  }; 
	\addplot+[name path=B] coordinates { 
 (0,6.91) 
 (10,7.75)
 (20,15.90) 
 (30,23.64) 
 (40,31.74)
 (50,43.52)
 (60,51.28)
 (70,53.51)
 (80,56.41)
 (90,63.08)
 (100,73.72)
  }; 
	
	%%Minima
	\addplot+[color=red!20,dashed,name path=C, mark=none] coordinates { 
 (0,6.81) 
 (10,7.52)
 (20,14.42) 
 (30,21.58) 
 (40,29.56)
 (50,41.44)
 (60,50.31)
 (70,52.74)
 (80,56.00)
 (90,62.14)
 (100,73.36)
  }; 

	%%Maxmima
	\addplot+[color=red!20,dashed,name path=D, mark=none] coordinates { 
 (0,7.02) 
 (10,8.02)
 (20,17.22) 
 (30,25.71) 
 (40,34.94)
 (50,45.26)
 (60,51.95)
 (70,53.88)
 (80,56.92)
 (90,64.20)
 (100,74.39)
  }; 	
	\addplot[red!20] fill between[of=C and D];
		
 \legend{CFD,Messung} 
 \end{axis} 
 \end{tikzpicture} 
 }\hfill 
 \subcaptionbox{SD Rechts}{ 
  \begin{tikzpicture} 
 \begin{axis}[ 
 height=10cm, 
 width=8cm,
 legend style={ 
 at={(0.5,-0.3)}, 
 anchor=north, 
 legend columns=-1 
 }, 
 ymin=0, 
 ymax=90,
 xmin=0, 
 xtick={20,40,60,80,100}, 
 ytick={0,10,20,30,40,50,60,70,80,90}, 
 ylabel={Temperatur in °C}, 
 xlabel={Klappenstellung in \%},
 ymajorgrids,
 xmajorgrids,
 nodes near coords, 
 every node near coord/.append style={font=\footnotesize}, 
 point meta=explicit symbolic, 
 ] 
 \addplot coordinates { 
 (0,6.064873943) 
 (10,5.272728089)
 (20,15.6922116) 
 (30,23.23744567) 
 (40,29.58409871)
 (50,40.69421012)
 (60,45.08954257)
 (70,51.30158893)
 (80,53.84531295)
 (90,66.89697259)
 (100,82.52502564)
  }; 
	\addplot coordinates { 
 (0,6.65) 
 (10,8.82)
 (20,16.35) 
 (30,23.90) 
 (40,33.49)
 (50,42.16)
 (60,48.69)
 (70,52.96)
 (80,56.90)
 (90,68.79)
 (100,72.82)
  }; 
	
	%%Minima
	\addplot+[color=red!20,dashed,name path=E, mark=none] coordinates { 
 (0,6.37) 
 (10,8.18)
 (20,15.58) 
 (30,22.63) 
 (40,31.80)
 (50,41.00)
 (60,48.12)
 (70,52.13)
 (80,56.13)
 (90,67.4)
 (100,72.32)
  };

	%%Maxmima
	\addplot+[color=red!20,dashed,name path=F, mark=none] coordinates { 
 (0,7.06) 
 (10,9.36)
 (20,18.13) 
 (30,25.92) 
 (40,36.28)
 (50,43.409)
 (60,49.260)
 (70,54.002)
 (80,58.0746)
 (90,70.482)
 (100,73.71)
  }; 	
	
	\addplot[red!20] fill between[of=E and F];
		
 %\legend{CFD,Messung} 
 \end{axis} 
 \end{tikzpicture} 
 }
 \subcaptionbox{Test}{
 \begin{tikzpicture} 
\begin{axis}[ 
 height=8cm, 
 width=8cm, 
 enlargelimits=0.05, 
 enlarge x limits={abs=30pt}, 
 legend style={ 
 at={(0.5,-0.3)}, 
 anchor=north, 
 legend columns=-1 
}, 
 ymin=0, 
 ymax=50, 
 x tick label style={/pgf/number format/1000 sep=}, 
 x tick label style={rotate=45,anchor=east}, 
 symbolic x coords={0,10,20,30,40,50,60,70,80,90,100},  
 xtick={0,20,40,60,80,100},   
 ylabel={Abweichung in \%}, 
 ybar, 
 bar width=8pt, 
 ytick={0,5,10,...,50}, 
 ymajorgrids, 
 %xminorgrids, 
 %minor x tick num=1, 
 %subtickwidth=0pt, 
 nodes near coords, 
 %nodes near coords style={font=\footnotesize},% in Version 1.12 noch nicht definiert 
 every node near coord/.append style={font=\footnotesize}, 
 point meta=explicit symbolic, 
] 
\addplot coordinates {        %%Messung
 (0,34.880305) 
 (10,44.2005968) 
 (20,34.30388548) 
 (30,17.11414479) 
 (40,7.682581804) 
 (50,5.468663576)
 (60,2.223792738)
 (70,2.719850801)
 (80,1.596997811)
 (90,7.620881019)
 (100,11.88505251
)

}; 
%\legend{Abwi} 
\end{axis}
\end{tikzpicture}
 }
  \subcaptionbox{Test2}{
 \begin{tikzpicture} 
\begin{axis}[ 
 height=8cm, 
 width=8cm, 
 enlargelimits=0.05, 
 enlarge x limits={abs=30pt}, 
 legend style={ 
 at={(0.5,-0.3)}, 
 anchor=north, 
 legend columns=-1 
}, 
 ymin=0, 
 ymax=50, 
 x tick label style={/pgf/number format/1000 sep=}, 
 x tick label style={rotate=45,anchor=east}, 
 symbolic x coords={0,10,20,30,40,50,60,70,80,90,100},  
 xtick={0,20,40,60,80,100},   
 ylabel={Abweichung in \%}, 
 ybar, 
 bar width=8pt, 
 ytick={0,5,10,...,50}, 
 ymajorgrids, 
 %xminorgrids, 
 %minor x tick num=1, 
 %subtickwidth=0pt, 
 nodes near coords, 
 %nodes near coords style={font=\footnotesize},% in Version 1.12 noch nicht definiert 
 every node near coord/.append style={font=\footnotesize}, 
 point meta=explicit symbolic, 
] 
\addplot coordinates {        %%Messung
 (0,34.880305) 
 (10,44.2005968) 
 (20,34.30388548) 
 (30,17.11414479) 
 (40,7.682581804) 
 (50,5.468663576)
 (60,2.223792738)
 (70,2.719850801)
 (80,1.596997811)
 (90,7.620881019)
 (100,11.88505251
)

}; 
%\legend{Abwi} 
\end{axis}
\end{tikzpicture}
 }
 \ref{legend:SD}
 \caption{Vergleich für verschiedene Netze von}
 \end{figure}

\end{document} 

MenschMax

Beitrag von MenschMax »

Ach und ich versuche die oberen beiden supcaptionboxen leer zu haben, ich benötige sie ja nur noch unter den beiden unteren Diagrammen. Gibt es da auch einen Befehl außer:
\subcaptionbox*{}
damit der Abstand dann auch kleiner wird zwischen den oberen und unteren Grafiken?

esdd
Forum-Meister
Forum-Meister
Beiträge: 2561
Registriert: So 7. Feb 2010, 16:36

Beitrag von esdd »

Eventuell suchst Du etwas wie
\documentclass[a4paper,12pt,twoside]{report} 
\usepackage[T1]{fontenc} 
\usepackage[utf8]{inputenc} 
\usepackage[ngerman]{babel} 
\usepackage{lmodern} 
\usepackage{subcaption} 
\usepackage{pgfplots}% lädt auch tikz 
\pgfplotsset{compat=newest}% compat immer setzen! 
\usepgfplotslibrary{fillbetween}

\usepackage{siunitx} 
\begin{document} 
\begin{figure}[htb]
\centering 
\begin{minipage}{.5\linewidth}
\raggedright
\begin{tikzpicture} 
 \begin{axis}[ 
 height=10cm, 
 width=7cm, 
 legend columns=-1,
 ymin=0, 
 ymax=90, 
 xmin=0, 
 xtick={20,40,60,80,100}, 
 ytick={0,10,20,30,40,50,60,70,80,90}, 
 ylabel={Temperatur in \si{\degreeCelsius}}, 
 xlabel={Klappenstellung in \%}, 
 grid=major, 
 legend to name={legend:SD} 
 ] 
 \addplot+[name path=A] coordinates { 
 (0,4.499674202) 
 (10,4.324053491) 
 (20,10.4473975) 
 (30,19.59755699) 
 (40,29.29712891) 
 (50,41.1387128) 
 (60,50.13531996) 
 (70,52.05104588) 
 (80,57.3142446) 
 (90,67.88965727) 
 (100,82.47613206) 
 }; 
 \addplot+[name path=B] coordinates { 
 (0,6.91) 
 (10,7.75) 
 (20,15.90) 
 (30,23.64) 
 (40,31.74) 
 (50,43.52) 
 (60,51.28) 
 (70,53.51) 
 (80,56.41) 
 (90,63.08) 
 (100,73.72) 
 }; 
 
 %%Minima 
 \addplot+[color=red!20,dashed,name path=C, mark=none] coordinates { 
 (0,6.81) 
 (10,7.52) 
 (20,14.42) 
 (30,21.58) 
 (40,29.56) 
 (50,41.44) 
 (60,50.31) 
 (70,52.74) 
 (80,56.00) 
 (90,62.14) 
 (100,73.36) 
 }; 
 
 %%Maxmima 
 \addplot+[color=red!20,dashed,name path=D, mark=none] coordinates { 
 (0,7.02) 
 (10,8.02) 
 (20,17.22) 
 (30,25.71) 
 (40,34.94) 
 (50,45.26) 
 (60,51.95) 
 (70,53.88) 
 (80,56.92) 
 (90,64.20) 
 (100,74.39) 
 }; 
 \addplot[red!20] fill between[of=C and D]; 
 
 \legend{CFD,Messung} 
 \end{axis} 
 \end{tikzpicture} 
 \end{minipage}%
\begin{minipage}{.5\linewidth}
 \raggedleft
 \begin{tikzpicture} 
 \begin{axis}[ 
 height=10cm, 
 width=7cm, 
 ymin=0, 
 ymax=90, 
 xmin=0, 
 xtick={20,40,60,80,100}, 
 ytick={0,10,20,30,40,50,60,70,80,90}, 
 %ylabel={Temperatur in \si{\degreeCelsius}}, 
 xlabel={Klappenstellung in \%}, 
 grid=major
 ] 
 \addplot coordinates { 
 (0,6.064873943) 
 (10,5.272728089) 
 (20,15.6922116) 
 (30,23.23744567) 
 (40,29.58409871) 
 (50,40.69421012) 
 (60,45.08954257) 
 (70,51.30158893) 
 (80,53.84531295) 
 (90,66.89697259) 
 (100,82.52502564) 
 }; 
 \addplot coordinates { 
 (0,6.65) 
 (10,8.82) 
 (20,16.35) 
 (30,23.90) 
 (40,33.49) 
 (50,42.16) 
 (60,48.69) 
 (70,52.96) 
 (80,56.90) 
 (90,68.79) 
 (100,72.82) 
 }; 
 
 %%Minima 
 \addplot+[color=red!20,dashed,name path=E, mark=none] coordinates { 
 (0,6.37) 
 (10,8.18) 
 (20,15.58) 
 (30,22.63) 
 (40,31.80) 
 (50,41.00) 
 (60,48.12) 
 (70,52.13) 
 (80,56.13) 
 (90,67.4) 
 (100,72.32) 
 }; 
 
 %%Maxmima 
 \addplot+[color=red!20,dashed,name path=F, mark=none] coordinates { 
 (0,7.06) 
 (10,9.36) 
 (20,18.13) 
 (30,25.92) 
 (40,36.28) 
 (50,43.409) 
 (60,49.260) 
 (70,54.002) 
 (80,58.0746) 
 (90,70.482) 
 (100,73.71) 
 }; 
 
 \addplot[red!20] fill between[of=E and F]; 
 \end{axis} 
 \end{tikzpicture} 
 \end{minipage}
 \par{\centering\ref{legend:SD}}\par\medskip
 \begin{minipage}{.5\linewidth}
 \raggedright
 \begin{tikzpicture} 
 \begin{axis}[ 
 height=8cm, 
 width=7cm, 
 enlargelimits=0.05, 
 enlarge x limits={abs=30pt}, 
 legend style={ 
 at={(0.5,-0.3)}, 
 anchor=north, 
 legend columns=-1 
 }, 
 ymin=0, 
 ymax=50, 
 x tick label style={rotate=45,anchor=east}, 
 symbolic x coords={0,10,20,30,40,50,60,70,80,90,100}, 
 xtick={0,20,40,60,80,100}, 
 ylabel={Abweichung in \%}, 
 ybar, 
 bar width=6pt, 
 ytick={0,5,10,...,50}, 
 ymajorgrids
 ] 
 \addplot coordinates { %%Messung 
 (0,34.880305) 
 (10,44.2005968) 
 (20,34.30388548) 
 (30,17.11414479) 
 (40,7.682581804) 
 (50,5.468663576) 
 (60,2.223792738) 
 (70,2.719850801) 
 (80,1.596997811) 
 (90,7.620881019) 
 (100,11.88505251 
 ) 
 }; 
 \end{axis} 
 \end{tikzpicture}
 \subcaption{Test 1}
 \end{minipage}%
 \begin{minipage}{.5\linewidth}
 \raggedleft
 \begin{tikzpicture} 
 \begin{axis}[ 
 height=8cm, 
 width=7cm, 
 enlargelimits=0.05, 
 enlarge x limits={abs=30pt}, 
 ymin=0, 
 ymax=50, 
 x tick label style={rotate=45,anchor=east}, 
 symbolic x coords={0,10,20,30,40,50,60,70,80,90,100}, 
 xtick={0,20,40,60,80,100}, 
 %ylabel={Abweichung in \%}, 
 ybar, 
 bar width=6pt, 
 ytick={0,5,10,...,50}, 
 ymajorgrids, 
 ] 
 \addplot coordinates { %%Messung 
 (0,34.880305) 
 (10,44.2005968) 
 (20,34.30388548) 
 (30,17.11414479) 
 (40,7.682581804) 
 (50,5.468663576) 
 (60,2.223792738) 
 (70,2.719850801) 
 (80,1.596997811) 
 (90,7.620881019) 
 (100,11.88505251 
 ) 
 }; 
 \end{axis} 
 \end{tikzpicture} 
 \subcaption{Test2}
 \end{minipage}

 \caption{Vergleich für verschiedene Netze von} 
 \end{figure} 
 
 \end{document} 

Antworten