Legendeneinträge rechtsbündig anordnen

Tabellen und Grafiken erstellen und anordnen


kannstmasehn
Forum-Century
Forum-Century
Beiträge: 165
Registriert: Mo 5. Mai 2014, 16:55

Legendeneinträge rechtsbündig anordnen

Beitrag von kannstmasehn »

Hallo,

ich möchte zwei Graphen plotten und dafür lediglich eine Legende nutzen. Das habe ich so weit hinbekommen, siehe Minimalbeispiel. Nun möchte ich die Einträge in der Legende rechtsbündig anordnen. Wie kann ich das realisieren?
\documentclass[margin=5mm]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{matrix,positioning}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=newest}

\begin{document}

	\begin{tikzpicture}
	\begin{groupplot}[group style={group size= 2 by 1}]
	\nextgroupplot	
	\addplot table[row sep=crcr]{%
		50	1.08606985986195\\
		69.7	1.0301192219201\\
	}; \label{plots:plot1}
	
	\addplot table[row sep=crcr]{%
		50	15.3733528550512\\
		69.7	11.8045387994143\\
	}; \label{plots:plot2}
	
	\addplot table[row sep=crcr]{%
		50	69.2846684793976\\
		69.7	53.5975737293453\\
	}; \label{plots:plot3}

	
	\coordinate (top) at (rel axis cs:0,1);% coordinate at top of the first plot
	
	\nextgroupplot	
	\addplot table[row sep=crcr]{%
		50	1.20572658060245\\
		69.7	1.09731876861966\\
	};
	
	\addplot table[row sep=crcr]{%
		50	23.1876861966236\\
		69.7	17.9245283018868\\
	};
	
	\addplot table[row sep=crcr]{%
		50	110.228401191658\\
		69.7	84.5746441575637\\
	};
	
	
	\coordinate (bot) at (rel axis cs:1,0);% coordinate at bottom of the last plot
	\end{groupplot}

	\path (top|-current bounding box.south)--
	coordinate(legendpos)
	(bot|-current bounding box.south);
	\matrix[
	matrix of nodes,
	draw,
	]at([yshift=0ex]legendpos)
	{
		\ref{plots:plot1}& blaaaaa&[5pt] \\
		\ref{plots:plot2}& blub&[5pt] \\
		\ref{plots:plot3}& bla&[5pt]
		\\};
	\end{tikzpicture}
\end{document}

Vielen Dank im Voraus.

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

Beitrag von Bartman »

Du könntest der \matrix das optionale Argument column 2/.style={anchor=east} hinzufügen.

kannstmasehn
Forum-Century
Forum-Century
Beiträge: 165
Registriert: Mo 5. Mai 2014, 16:55

Beitrag von kannstmasehn »

Danke dir. Funktioniert bei zwei Spalten leider nur für die erste. Wie kann ich das auch bei der zweiten, bzw. bei einer dritten oder allen Spalten umsetzen? Zumal da noch hinzukommt, dass der Legendeneintrag nicht mehr auf der gleichen Höhe wie das Legendensymbol ist.
\documentclass[margin=5mm]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{matrix,positioning}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=newest}
%\usepackage{tikz}

\begin{document}

	\begin{tikzpicture}
	\begin{groupplot}[group style={group size= 2 by 1}]
	\nextgroupplot	
	\addplot table[row sep=crcr]{%
		50	1.08606985986195\\
		69.7	1.0301192219201\\
	}; \label{plots:plot1}
	
	\addplot table[row sep=crcr]{%
		50	15.3733528550512\\
		69.7	11.8045387994143\\
	}; \label{plots:plot2}
	
	\addplot table[row sep=crcr]{%
		50	69.2846684793976\\
		69.7	53.5975737293453\\
	}; \label{plots:plot3}

	\addplot table[row sep=crcr]{%
	50	90\\
	69.7	70\\
	}; \label{plots:plot4}

	
	\coordinate (top) at (rel axis cs:0,1);% coordinate at top of the first plot
	
	\nextgroupplot	
	\addplot table[row sep=crcr]{%
		50	1.20572658060245\\
		69.7	1.09731876861966\\
	};
	
	\addplot table[row sep=crcr]{%
		50	23.1876861966236\\
		69.7	17.9245283018868\\
	};
	
	\addplot table[row sep=crcr]{%
		50	110.228401191658\\
		69.7	84.5746441575637\\
	};
	
	\addplot table[row sep=crcr]{%
		50	90\\
		69.7	70\\
	}; 
	
	\coordinate (bot) at (rel axis cs:1,0);% coordinate at bottom of the last plot
	\end{groupplot}

	\path (top|-current bounding box.south)--
	coordinate(legendpos)
	(bot|-current bounding box.south);
	\matrix[
	matrix of nodes,
	draw,
	column 2/.style={anchor=east},
	]at([yshift=-5ex]legendpos)
	{
		\ref{plots:plot1}& blaaaaa&[5pt] 
		\ref{plots:plot2}& blaaaaa&[5pt] \\
		\ref{plots:plot3}& blub&[5pt]
		\ref{plots:plot4}& blub&[5pt]		
		\\};
	\end{tikzpicture}
\end{document}

Danke dir!

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

Beitrag von esdd »

Nimm every even column/.style={anchor=base east}, also
\documentclass[margin=5mm]{standalone}
\usepackage{pgfplots}% lädt auch tikz
\pgfplotsset{compat=newest}% direkt nach dem Laden von pgfplots setzen
\usetikzlibrary{matrix,positioning}
\usepgfplotslibrary{groupplots}

\begin{document}
   \begin{tikzpicture}
   \begin{groupplot}[group style={group size= 2 by 1}]
   \nextgroupplot   
   \addplot table[row sep=crcr]{%
      50   1.08606985986195\\
      69.7   1.0301192219201\\
   }; \label{plots:plot1}
   
   \addplot table[row sep=crcr]{%
      50   15.3733528550512\\
      69.7   11.8045387994143\\
   }; \label{plots:plot2}
   
   \addplot table[row sep=crcr]{%
      50   69.2846684793976\\
      69.7   53.5975737293453\\
   }; \label{plots:plot3}

   \addplot table[row sep=crcr]{%
   50   90\\
   69.7   70\\
   }; \label{plots:plot4}

   
   \coordinate (top) at (rel axis cs:0,1);% coordinate at top of the first plot
   
   \nextgroupplot   
   \addplot table[row sep=crcr]{%
      50   1.20572658060245\\
      69.7   1.09731876861966\\
   };
   
   \addplot table[row sep=crcr]{%
      50   23.1876861966236\\
      69.7   17.9245283018868\\
   };
   
   \addplot table[row sep=crcr]{%
      50   110.228401191658\\
      69.7   84.5746441575637\\
   };
   
   \addplot table[row sep=crcr]{%
      50   90\\
      69.7   70\\
   }; 
   
   \coordinate (bot) at (rel axis cs:1,0);% coordinate at bottom of the last plot
   \end{groupplot}

   \path (top|-current bounding box.south)--
   coordinate(legendpos)
   (bot|-current bounding box.south);
   \matrix[
   matrix of nodes,
   draw,
   every even column/.style={anchor=base east},
   ]at([yshift=-5ex]legendpos)
   {
      \ref{plots:plot1}& blaaaaa&[5pt] 
      \ref{plots:plot2}& blaaaaa&[5pt] \\
      \ref{plots:plot3}& blub&[5pt]
      \ref{plots:plot4}& blub&[5pt]      
      \\};
   \end{tikzpicture}
\end{document}
[/code]

kannstmasehn
Forum-Century
Forum-Century
Beiträge: 165
Registriert: Mo 5. Mai 2014, 16:55

Beitrag von kannstmasehn »

Danke. Passt!

Antworten