Seite 1 von 1

Eigene Farbenliste pgfplots erstellen

Verfasst: Di 23. Apr 2019, 11:50
von kannstmasehn
Hallo,

ich möchte Graphen erzeugen, bei denen die einzelnen Messreihen sich durch verschiedene Marker und Farben unterscheiden. Das mit den Markern habe ich hinbekommen. Für die Farben habe ich nun Color Brewer genutzt, jedoch bin ich mit der ganzen Farbenpalette nicht so zufrieden (gelb ist zb oft enthalten und nicht so schön zu drucken), weshalb ich gerne eine eigene Farbliste erstellen möchte. Wie kann ich das umsetzen?

Mein bisheriges Beispiel:
\documentclass[a4paper]{scrbook}
\usepackage{pgfplots}
\usetikzlibrary{pgfplots.colorbrewer}

\pgfplotsset{
	cycle list/.define={my marks}{
		every mark/.append style={solid,fill=\pgfkeysvalueof{/pgfplots/mark list fill}},mark=*\\
		every mark/.append style={solid,fill=\pgfkeysvalueof{/pgfplots/mark list fill}},mark=star\\
		every mark/.append style={solid,fill=\pgfkeysvalueof{/pgfplots/mark list fill}},mark=square\\
		every mark/.append style={solid,fill=\pgfkeysvalueof{/pgfplots/mark list fill}},mark=+\\	
		every mark/.append style={solid,fill=\pgfkeysvalueof{/pgfplots/mark list fill}},mark=triangle\\
		every mark/.append style={solid,fill=\pgfkeysvalueof{/pgfplots/mark list fill}},mark=x\\	
		every mark/.append style={solid,fill=\pgfkeysvalueof{/pgfplots/mark list fill}},mark=pentagon\\
		every mark/.append style={solid,fill=\pgfkeysvalueof{/pgfplots/mark list fill}},mark=o\\
		every mark/.append style={solid,fill=\pgfkeysvalueof{/pgfplots/mark list fill}},mark=diamond\\
	},
}

\usepackage{pgfplots}
\usepgfplotslibrary{colorbrewer}
\pgfplotsset{
	cycle list/Paired-10,
	cycle multiindex* list={
		my marks\nextlist
		Paired-10\nextlist
	},
}

\begin{document}
	
		\begin{tikzpicture}
		\begin{axis}[
		legend style={at={(1.03,0.5)}, anchor=west, legend cell align=left, align=left, draw=white!15!black}
		]
		\addplot {rnd};
		\addlegendentry{1}
		
		\addplot {rnd-1};
		\addlegendentry{2}
		
		\addplot {rnd-2};
		\addlegendentry{3}
		
		\addplot {rnd-3};
		\addlegendentry{4}
		
		\addplot {rnd-4};
		\addlegendentry{5}
		
		\addplot {rnd-5};
		\addlegendentry{6}
		
		\addplot {rnd-6};
		\addlegendentry{7}
		
		\addplot {rnd-7};
		\addlegendentry{8}
		
		\addplot {rnd-8};
		\addlegendentry{9}
		
		\addplot {rnd-9};
		\addlegendentry{10}
		
		\addplot {rnd-10};
		\addlegendentry{11}		
		
		\end{axis}
		\end{tikzpicture}

\end{document}

Vielen Dank im Voraus.

Verfasst: Mi 24. Apr 2019, 10:46
von esdd
Du lädst sowohl pgfplots als auch die colorbrewer Bibliothek zwei Mal, dafür fehlt das Setzen von compat direkt nach dem Laden des Pakets.

Du könntest zum einen direkt die schon definierte color list verwenden:
\documentclass[a4paper]{scrbook} 
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}% <- aktuelle Version ist 1.16

\pgfplotsset{ 
   cycle list/.define={my marks}{ 
      every mark/.append style={solid,fill=\pgfkeysvalueof{/pgfplots/mark list fill}},mark=*\\ 
      every mark/.append style={solid,fill=\pgfkeysvalueof{/pgfplots/mark list fill}},mark=star\\ 
      every mark/.append style={solid,fill=\pgfkeysvalueof{/pgfplots/mark list fill}},mark=square\\ 
      every mark/.append style={solid,fill=\pgfkeysvalueof{/pgfplots/mark list fill}},mark=+\\   
      every mark/.append style={solid,fill=\pgfkeysvalueof{/pgfplots/mark list fill}},mark=triangle\\ 
      every mark/.append style={solid,fill=\pgfkeysvalueof{/pgfplots/mark list fill}},mark=x\\   
      every mark/.append style={solid,fill=\pgfkeysvalueof{/pgfplots/mark list fill}},mark=pentagon\\ 
      every mark/.append style={solid,fill=\pgfkeysvalueof{/pgfplots/mark list fill}},mark=o\\ 
      every mark/.append style={solid,fill=\pgfkeysvalueof{/pgfplots/mark list fill}},mark=diamond\\ 
   }, 
  cycle multiindex* list={
    my marks\nextlist 
    color list\nextlist
  }
}

\begin{document} 
\begin{tikzpicture} 
  \begin{axis}[ 
    legend style={at={(1.03,0.5)}, anchor=west, legend cell align=left, align=left, draw=white!15!black} 
  ] 
  \addplot {rnd};\addlegendentry{1}
  \addplot {rnd-1};\addlegendentry{2}
  \addplot {rnd-2};\addlegendentry{3}
  \addplot {rnd-3};\addlegendentry{4}
  \addplot {rnd-4};\addlegendentry{5}
  \addplot {rnd-5};\addlegendentry{6}
  \addplot {rnd-6};\addlegendentry{7}
  \addplot {rnd-7};\addlegendentry{8}
  \addplot {rnd-8};\addlegendentry{9}
  \addplot {rnd-9};\addlegendentry{10}
  \addplot {rnd-10};\addlegendentry{11}
  \end{axis} 
\end{tikzpicture} 
\end{document}
Zum anderen kannst Du natürlich genauso eine eigene Liste mit Farben erstellen, wie Du es für die Marker getan hast:
\documentclass[a4paper]{scrbook} 
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}% <- aktuelle Version ist 1.16

\pgfplotsset{ 
   cycle list/.define={my marks}{ 
      every mark/.append style={solid,fill=\pgfkeysvalueof{/pgfplots/mark list fill}},mark=*\\ 
      every mark/.append style={solid,fill=\pgfkeysvalueof{/pgfplots/mark list fill}},mark=star\\ 
      every mark/.append style={solid,fill=\pgfkeysvalueof{/pgfplots/mark list fill}},mark=square\\ 
      every mark/.append style={solid,fill=\pgfkeysvalueof{/pgfplots/mark list fill}},mark=+\\   
      every mark/.append style={solid,fill=\pgfkeysvalueof{/pgfplots/mark list fill}},mark=triangle\\ 
      every mark/.append style={solid,fill=\pgfkeysvalueof{/pgfplots/mark list fill}},mark=x\\   
      every mark/.append style={solid,fill=\pgfkeysvalueof{/pgfplots/mark list fill}},mark=pentagon\\ 
      every mark/.append style={solid,fill=\pgfkeysvalueof{/pgfplots/mark list fill}},mark=o\\ 
      every mark/.append style={solid,fill=\pgfkeysvalueof{/pgfplots/mark list fill}},mark=diamond\\ 
   }, 
  cycle list/.define={my colors}{red,gray,blue,green!70!black},
  cycle multiindex* list={
    my marks\nextlist 
    my colors\nextlist
  }
}

\begin{document} 
\begin{tikzpicture} 
  \begin{axis}[ 
    legend style={at={(1.03,0.5)}, anchor=west, legend cell align=left, align=left, draw=white!15!black} 
  ] 
  \addplot {rnd};\addlegendentry{1}
  \addplot {rnd-1};\addlegendentry{2}
  \addplot {rnd-2};\addlegendentry{3}
  \addplot {rnd-3};\addlegendentry{4}
  \addplot {rnd-4};\addlegendentry{5}
  \addplot {rnd-5};\addlegendentry{6}
  \addplot {rnd-6};\addlegendentry{7}
  \addplot {rnd-7};\addlegendentry{8}
  \addplot {rnd-8};\addlegendentry{9}
  \addplot {rnd-9};\addlegendentry{10}
  \addplot {rnd-10};\addlegendentry{11}
  \end{axis} 
\end{tikzpicture} 
\end{document}
In beiden Fällen brauchst Du dann die colorbrewer Bibliothek nicht.

Verfasst: Do 25. Apr 2019, 11:28
von kannstmasehn
Super, danke dir!

Habe mir nun folgendes zusammengebaut:
\documentclass[a4paper]{scrbook}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}% <- aktuelle Version ist 1.16

\pgfplotsset{
	cycle list/.define={my marks}{
		every mark/.append style={solid,fill=\pgfkeysvalueof{/pgfplots/mark list fill}},mark=*\\
	},
}

\definecolor{matlab1}{rgb}{0, 0.4470, 0.7410}
\definecolor{matlab2}{rgb}{0.8500, 0.3250, 0.0980}

\pgfplotscreateplotcyclelist{matlab}{
	{matlab1,solid},
}

\pgfplotsset{cycle list name=matlab,cycle multiindex* list={
		my marks\nextlist
		matlab\nextlist}
}

\begin{document}
	
	\begin{tikzpicture}
	\begin{axis}[
	legend style={at={(1.03,0.5)}, anchor=west, legend cell align=left, align=left, draw=white!15!black}
	]
	\addplot {rnd};
	\addlegendentry{1}
	
	\addplot {rnd-1};
	\addlegendentry{2}	
	
	\end{axis}
	\end{tikzpicture}
	
\end{document}
Dabei fällt mir auf, dass die Füllung von mark=* nicht exakt der Farbe entspricht, wie die Linie ist. Wie kann ich das anpassen?

Vielen Dank im Voraus.

Verfasst: Do 25. Apr 2019, 22:51
von esdd
kannstmasehn hat geschrieben: Dabei fällt mir auf, dass die Füllung von mark=* nicht exakt der Farbe entspricht, wie die Linie ist. Wie kann ich das anpassen?
Aber die Füllung mit einer etwas dunkleren Farbe hast Du doch mit
fill=\pgfkeysvalueof{/pgfplots/mark list fill}
selbst eingestellt? Initialisiert ist der Schlüssel mit .!80!black. Ist die aktuelle Farbe beispielsweise red, dann wird dadurch mit red!80!black statt red gefüllt.

Wenn Du das nicht möchtest, dann lösche das einfach wieder und verwende nur
every mark/.append style={solid},mark=*\\

Verfasst: Fr 26. Apr 2019, 09:07
von kannstmasehn
Super, funktioniert! Vielen Dank.
\documentclass[a4paper]{scrbook}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\pgfplotsset{
	cycle list/.define={my marks}{
		every mark/.append style={solid},mark=* \\
		every mark/.append style={solid},mark=star\\
	},
}

\definecolor{matlab1}{rgb}{0, 0.4470, 0.7410}
\definecolor{matlab2}{rgb}{0.8500, 0.3250, 0.0980}

\pgfplotscreateplotcyclelist{matlab}{
	{matlab1,solid},
	{matlab2,solid},
}

\pgfplotsset{cycle list name=matlab,cycle multiindex* list={
		my marks\nextlist
		matlab\nextlist}
}

\begin{document}
	
	\begin{tikzpicture}
	\begin{axis}[
	legend style={at={(1.03,0.5)}, anchor=west, legend cell align=left, align=left, draw=white!15!black}
	]
	\addplot {rnd};
	\addlegendentry{1}
	
	\addplot {rnd-1};
	\addlegendentry{2}
		
	
	\end{axis}
	\end{tikzpicture}
	
\end{document}