PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : pgfplots, xtick=data: Koordinaten mit selben y-Wert nebeneinander malen?



RingoP601
18-09-2012, 15:09
Hallo,

ich habe seit Tagen im Netz gesucht aber keine Info gefunden. Hier mein Problem:

Ich habe ein Diagramm mit PGFPLOTS, das als x-Achse
xtick=data hat.
Des Weiteren habe ich pro xtick 4 Werte, die ich als Quadrate und Dreiecke eintrage.

So lange die Werte alle unterchiedlich sind, bin ich zufrieden und man kann alles erkennen.
Problem ist, für die Instanz 1 habe ich 3 mal den selben Wert. Durch die bisherige Konstruktion übermalt tikz mit dem zweiten Dreieck das erste und es sieht aus, als ob Algo 2 keinen Wert hat für Instanz 1.

Ich hätte gern, dass bei gleichen Werten die Symbole einfach nebeneinander gemalt werden. Platz ist dafür ja da. Doch hat scheinbar vor mir nie jemand ein ähnliches Problem gehabt oder ich habe falsch gesucht :-(
Kann mir nicht vorstellen, dass das nicht gehen soll. Ich nehme auch gern ne Lösung mit Brecheisen ;-)

Voraussetzungen:
Die Symbole müssen so bleiben und ich will KEINE Kurve durch die Punkte zeichnen.
Ich habe für mein echtes Diagramm sehr viele Instanzen, wodurch ein Balkendiagramm sehr hässlich wird. Ich kann das Diagramm aus inhaltlichen Gründen nicht in zwei aufteilen.

Minimalbeispiel:



\begin{tikzpicture}
\begin{semilogyaxis}
[
xlabel={Instanzen},
ylabel={Laufzeit Algorithmus in ms},
ymin=0,ymax=1000,
xtick = data,
yticklabel={%
\pgfplotsset{/pgf/fpu}% <-- erweiterter zahlenbereich
\pgfmathparse{exp(\tick)}% exponentiere den exponent
\pgfmathprintnumber[fixed]{\pgfmathresult}% formatiere die zahl
},
y tick label style={/pgf/number format/use comma, /pgf/number format/1000 sep={.}},
x tick label style={rotate=45,anchor=east},
legend pos=north west, %,legend columns=-1},
symbolic x coords={Instanz 1, Instanz 2, Instanz 3}
]
\addplot[color=green, draw=black, mark=square*,only marks]coordinates{
(Instanz 1, 46) (Instanz 2, 515) (Instanz 3, 109)
};
\addlegendentry{Algo 1}

\addplot[color=blue, draw=black, mark=triangle*,only marks] coordinates{
(Instanz 1, 31) (Instanz 2, 421) (Instanz 3, 94)
};
\addlegendentry{Algo 2}

\addplot[color=yellow, draw=black, mark=square*,only marks] coordinates{
(Instanz 1, 31) (Instanz 2, 187) (Instanz 3, 62)
};
\addlegendentry{Algo 3}

\addplot[color=magenta, draw=black, mark=triangle*,only marks] coordinates{
(Instanz 1, 31) (Instanz 2, 140) (Instanz 3, 47)
};
\addlegendentry{Algo 4}
\end{semilogyaxis}
\end{tikzpicture}


Danke, viele Grüße

Ringo

hakaze
18-09-2012, 16:21
Pgfplots ist sehr penibel mit Leerzeichen bei symbolischen Koordinatenangaben

The ⟨dictionary⟩ can be a comma separated list or a list terminated with ‘\\’. In both cases, white space is considered to be part of the names (use ‘%’ at end of lines).Das heißt, du musst sowohl in der Liste als auch bei den Koordinatenangaben darauf achten, keine zusätzlichen Leerzeichen vor/nach Klammer und Kommas einzufügen.

Ansonsten könnte man es auch ohne symbolische Werte machen und nur die Beschriftung der Anstriche (ticks) vorgeben. Dann sind die Leerzeichen nicht mehr sooo wichtig:
\documentclass{standalone}

\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{semilogyaxis}
[
xlabel={Instanzen},
ylabel={Laufzeit Algorithmus in ms},
ymin=0,ymax=1000,
xtick = data,
yticklabel={%
\pgfplotsset{/pgf/fpu}% <-- erweiterter zahlenbereich
\pgfmathparse{exp(\tick)}% exponentiere den exponent
\pgfmathprintnumber[fixed]{\pgfmathresult}% formatiere die zahl
},
y tick label style={/pgf/number format/use comma, /pgf/number format/1000 sep={.}},
%x tick label style={rotate=45,anchor=east},
legend pos=north west, %,legend columns=-1},
xticklabels={Instanz 1, Instanz 2, Instanz 3}
]
\addplot[color=green, draw=black, mark=square*,only marks]coordinates{
(1, 46) ( 2, 515) (3, 109)
};
\addlegendentry{Algo 1}

\addplot[color=blue, draw=black, mark=triangle*,only marks,mark size=4pt] coordinates{
(1, 31) ( 2, 421) ( 3, 94)
};
\addlegendentry{Algo 2}

\addplot[color=yellow, draw=black, mark=square*,only marks] coordinates{
( 1, 31) ( 2, 187) ( 3, 62)
};
\addlegendentry{Algo 3}

\addplot[color=magenta, draw=black, mark=triangle*,only marks] coordinates{
( 3, 31) ( 3, 140) ( 3, 47)
};
\addlegendentry{Algo 4}
\end{semilogyaxis}
\end{tikzpicture}
\end{document}

RingoP601
18-09-2012, 16:29
Danke für den Tipp, aber mit Leerzeichen hab ich keine Probleme :)
(hatte copy-paste-fehler bei dem letzten addplot, ist nun gefixt.)

Das Problem ist, ich habe 3 mal den selben Koordinatenwert (Instanz 1, 31) und ich möchte gern alle 3 Werte als Symbol im Diagramm sehen.
Am besten nebeneinander :D

Bisher werden die Symbole alle übereinander gemalt, was ja in gewisser Weise auch korrekt ist.

Hab gesehen, du hast ein Symbol größer gemacht, das ist zumindest schon mal ne brauchbare Idee, falls nix weiter geht!

hakaze
18-09-2012, 16:55
Noch ist das Problem mit den Leerzeichen zumind. noch in deinem Beispiel-Code drin:
(Instanz 1, 46) ( Instanz 2, 515) (Instanz 3, 109) Das führt zumind. bei mir zu einem Fehler.

Zu deinem anderen Problem habe ich hier eine vielleicht auch für dich brauchbare Lösung (http://tex.stackexchange.com/q/44547/17198) gefunden. Bsp.:
\documentclass{standalone}

\usepackage{pgfplots}
\pgfplotsset{
jitter/.style={
x filter/.code={\pgfmathparse{\pgfmathresult+rnd*#1}}
},
jitter/.default=0.1
}

\begin{document}
\begin{tikzpicture}
\begin{semilogyaxis}
[
xlabel={Instanzen},
ylabel={Laufzeit Algorithmus in ms},
ymin=0,ymax=1000,
xtick = data,
yticklabel={%
\pgfplotsset{/pgf/fpu}% <-- erweiterter zahlenbereich
\pgfmathparse{exp(\tick)}% exponentiere den exponent
\pgfmathprintnumber[fixed]{\pgfmathresult}% formatiere die zahl
},
y tick label style={/pgf/number format/use comma, /pgf/number format/1000 sep={.}},
x tick label style={rotate=45,anchor=east},
legend pos=north west, %,legend columns=-1},
symbolic x coords={Instanz 1, Instanz 2, Instanz 3}, jitter=0.2
]
\addplot[color=green, draw=black, mark=square*,only marks]coordinates{
(Instanz 1, 46) ( Instanz 2, 515) (Instanz 3, 109)
};
\addlegendentry{Algo 1}

\addplot[color=blue, draw=black, mark=triangle*,only marks] coordinates{
(Instanz 1, 31) (Instanz 2, 421) (Instanz 3, 94)
};
\addlegendentry{Algo 2}

\addplot[color=yellow, draw=black, mark=square*,only marks] coordinates{
(Instanz 1, 31) (Instanz 2, 187) (Instanz 3, 62)
};
\addlegendentry{Algo 3}

\addplot[color=magenta, draw=black, mark=triangle*,only marks] coordinates{
(Instanz 1, 31) (Instanz 2, 140) (Instanz 3, 47)
};
\addlegendentry{Algo 4}
\end{semilogyaxis}
\end{tikzpicture}
\end{document}

RingoP601
18-09-2012, 17:37
OK, nun ist das Leerzeichen weg ;)
Ich sag nur copy-paste... Hatte das Ding aus meinem Diagramm erstellet und nicht auf Fehler getestet. Nun ists getestet und es hat keine Fehler mehr :)

Ja, das sieht schon ganz vernünftig aus :)

Danke.