Legende pgfplots Legendeneinträge zusammenfassen

Tabellen und Grafiken erstellen und anordnen


eduardinho
Forum-Anfänger
Forum-Anfänger
Beiträge: 25
Registriert: Mi 22. Aug 2012, 13:06

Legende pgfplots Legendeneinträge zusammenfassen

Beitrag von eduardinho »

Hallo zusammen,

ich habe folgendes Problem:
ich habe 3 Messergebnisse in einem semilogarithmischen Diagramm. Für diese habe ich einen fit erstellt und ebenfalls in mein Diagramm gezeichnet. Da zwei Linien aber fast übereinander liegen, habe ich die farblich voneinander abgehoben und die Fits sollen mit in die Legende. Was ich jetzt aber habe sind 6 Einträge für 3 Datensätze, jeweils einmal als Punkt, einmal als Linie. Was ich gerne hätte ist, in der Legende Punkt und Linie übereinander legen, so dass ich nur noch drei Einträge mit jeweils Punkt und Linie habe. Sorry ist recht umständlich formuliert aber ich hoffe es kommt rüber.

Anbei das Minimalbeispiel, wie es jetzt ungefähr aussieht.
\documentclass{scrartcl} 
\usepackage{pgfplots} 
\pgfplotsset{/pgf/number format/use comma} 
\usetikzlibrary{patterns} 

\begin{filecontents*}{data.txt} 
xa	ya	xb	yb	xc	yc
1	1.1	1	1.09	1	1
3000	0.75	3000	0.7	3000	0.9
100000	0.45	100000	0.5	1000000	0.7
\end{filecontents*} 

\begin{document} 

\begin{tikzpicture}
   \begin{semilogxaxis}[ 
%    width=10cm,
   	xlabel={x},
   	ylabel={y},
   	ymin=0, ymax=1.1,
   	xmin=1, 
 	xtick align=inside,
	ymajorgrids=true,
	xmajorgrids=true,
%	xminorgrids=true,
	legend style={at={(0.05,0.05)}, anchor=south west},
	legend cell align=left,
	legend entries={A, B, C, A, B, C}
   	] 
     \addplot+[only marks] table[x=xa, y=ya] {data.txt};
     \addplot+[only marks] table[x=xb, y=yb] {data.txt};
     \addplot[only marks,green,mark=triangle*] table[x=xc, y=yc] {data.txt};
     \addplot[blue,domain=1:2000000]{1.1-0.12*log10(x)};
     \addplot[red,dashdotted,domain=1:2000000]{1.09-0.11*log10(x)};
     \addplot[green,dashed,domain=1:2000000]{1-0.05*log10(x)};
   \end{semilogxaxis}
\end{tikzpicture}

\end{document} 
Vielen Dank euch!

eduardinho
Forum-Anfänger
Forum-Anfänger
Beiträge: 25
Registriert: Mi 22. Aug 2012, 13:06

Beitrag von eduardinho »

ich habe jetzt folgenden Foreneintrag gefunden:
http://www.mrunix.de/forums/showthread. ... mmenfassen

mit

forget plot

und

legend image post style={mark=*}

würde ich es schonmal hinbekommen, dass ich Punkte über den Linien darstellen kann. Jedoch will ich ja nicht nur bei einem der drei einen Punkt in der Legende haben...
jemand eine Idee, wie ich das weiter anpassen könnte?

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

Beitrag von esdd »

Dann sortiere die Plots entsprechend und wende das 3x an:
\documentclass{scrartcl} 
\usepackage{pgfplots} 
\pgfplotsset{/pgf/number format/use comma} 
\usetikzlibrary{patterns} 

\begin{filecontents*}{data.txt} 
 xa   ya   xb   yb   xc   yc 
 1   1.1   1   1.09   1   1 
 3000   0.75   3000   0.7   3000   0.9 
 100000   0.45   100000   0.5   1000000   0.7 
\end{filecontents*} 

\begin{document} 

\begin{tikzpicture} 
    \begin{semilogxaxis}[ 
%    width=10cm, 
       xlabel={x}, 
       ylabel={y}, 
       ymin=0, ymax=1.1, 
       xmin=1, 
     xtick align=inside, 
    ymajorgrids=true, 
    xmajorgrids=true, 
%   xminorgrids=true, 
    legend style={at={(0.05,0.05)}, anchor=south west}, 
    legend cell align=left, 
    legend entries={A, B, C} 
       ] 
      \addplot+[only marks,forget plot] table[x=xa, y=ya] {data.txt};
      \addplot+[mark=none,domain=1:2000000,legend image post style={mark=*}]{1.1-0.12*log10(x)};  
      \addplot+[only marks,forget plot] table[x=xb, y=yb] {data.txt};
      \addplot+[mark=none,dashdotted,domain=1:2000000,legend image post style={mark=square*}]{1.09-0.11*log10(x)};  
      \addplot[only marks,green,mark=triangle*,forget plot] table[x=xc, y=yc] {data.txt}; 
      \addplot[green,dashed,domain=1:2000000,legend image post style={mark=square*}]{1-0.05*log10(x)}; 
    \end{semilogxaxis} 
\end{tikzpicture} 
\end{document}
Gruß
Elke

Bild
Dateianhänge
gl_zleg.png
gl_zleg.png (13.8 KiB) 2494 mal betrachtet

eduardinho
Forum-Anfänger
Forum-Anfänger
Beiträge: 25
Registriert: Mi 22. Aug 2012, 13:06

Beitrag von eduardinho »

Hallo Elke,

ah, das war ja doch einfacher als ich dachte... ich dachte der Befehl darf nur oben rein...

Danke schön!

Jetzt habe ich noch ein kleines Problem, dass durch die dashed, dotted, dashdotted... Linien entsteht. Was mir vorher nicht bewusst war ist, dass pgfplots anscheinend eine Linie um die Punkte zieht, dadurch sieht das ganze in der Legende arg zerstückelt aus, siehe Anhang. Die durchgezogene Linie sieht ja normal aus, bei den anderen Linien, eher wie ein Grafikfehler...

Könnt ihr mir da weiterhelfen, kann man das irgendwie verhindern oder schöner gestalten?
Dateianhänge
Unbenannt-1.JPG
Unbenannt-1.JPG (14.13 KiB) 2466 mal betrachtet
Unbenannt-2.JPG
Unbenannt-2.JPG (13.78 KiB) 2468 mal betrachtet

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

Beitrag von esdd »

Aus irgendeinem Grund funktioniert mark options={draw=none} nicht, aber vermutlich reicht Dir ja, wenn die Linien um die Marker durchgezogen werden:
legend image post style={mark options=solid,mark=square*}
Gruß
Elke

Antworten