PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : gleiche Farbreihenfolge in pgfplots wie in MATLAB



Magger
25-06-2012, 13:43
Hallo alle zusammen,

ich habe ausnahmsweise mal nicht nur eine Frage, sondern gleich dazu eine Antwort.

Wenn man beim Erstellen von Diagrammen mit Hilfe von TikZ/pgfplots die gleiche Farbreihenfolge (Blau, Grün, Rot, ...) wie beim Plotten in MATLAB haben möchte, kann man die Einstellungen aus folgendem Minimalbeispiel übernehmen.


\documentclass{scrartcl}

\usepackage{tikz}

\usepackage{pgfplots}

\definecolor{matlab1}{rgb}{0,0,1}
\definecolor{matlab2}{rgb}{0,0.5,0}
\definecolor{matlab3}{rgb}{1,0,0}
\definecolor{matlab4}{rgb}{0,0.75,0.75}
\definecolor{matlab5}{rgb}{0.75,0,0.75}
\definecolor{matlab6}{rgb}{0.75,0.75,0}
\definecolor{matlab7}{rgb}{0.25,0.25,0.25}

\pgfplotscreateplotcyclelist{matlab}{
{matlab1,solid},
{matlab2,dashed},
{matlab3,dashdotted},
{matlab4,dotted},
{matlab5,densely dashed},
{matlab6,densely dashdotted},
{matlab7,densely dotted},
}

\pgfplotsset{cycle list name=matlab}

\begin{document}

\begin{tikzpicture}
\begin{axis}[stack plots=y,stack dir=minus]
\addplot coordinates {(0,1) (0.5,1) (1,1)};
\addplot coordinates {(0,1) (0.5,1) (1,1)};
\addplot coordinates {(0,1) (0.5,1) (1,1)};
\addplot coordinates {(0,1) (0.5,1) (1,1)};
\addplot coordinates {(0,1) (0.5,1) (1,1)};
\addplot coordinates {(0,1) (0.5,1) (1,1)};
\addplot coordinates {(0,1) (0.5,1) (1,1)};
\addplot coordinates {(0,1) (0.5,1) (1,1)};
\addplot coordinates {(0,1) (0.5,1) (1,1)};
\addplot coordinates {(0,1) (0.5,1) (1,1)};
\addplot coordinates {(0,1) (0.5,1) (1,1)};
\addplot coordinates {(0,1) (0.5,1) (1,1)};
\addplot coordinates {(0,1) (0.5,1) (1,1)};
\end{axis}
\end{tikzpicture}

\end{document}

Es werden zuerst die 7 Farben wie in MATLAB definiert, dann eine cycle list angelegt und diese als Standardeinstellung festgelegt. Das Ergebnis sieht man im dem beispielhaften Plot (wie im Handbuch von pgfplots).