在 pgfplots 循环列表中使用颜色系列

在 pgfplots 循环列表中使用颜色系列

我知道,如果我提供要循环的颜色的明确列表,我可以定义一个新的循环列表供pgfplots使用。我怎样才能改为使用使用定义的颜色系列,即循环该颜色系列?\pgfplotscreateplotcyclelistxcolor\definecolorseries

用于测试的 MWE:

\documentclass{article}

\usepackage{pgfplots}

% Define a color series.
\definecolorseries{foo}{hsb}{step}[hsb]{0,1,1}[hsb]{.618,0,0}
\resetcolorseries{foo}

% Now use that color series in a cycle list.
\pgfplotscreateplotcyclelist{mylist}{}

\begin{document}

{\color{foo!![6]}Hello}

\begin{tikzpicture}
  \begin{axis} [
        stack plots=y,
        stack dir=minus,
        cycle list name=mylist,
      ]
    \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}

答案1

除了线条颜色,循环列表 中pgfplots还可以控制其他方面,如绘图模式、标记形状和标记选项。以下示例将颜色系列foo(实际使用的颜色规范是foo!![<n>])设置为绘图颜色。您可能还想foo在标记选项中将其用作该系列的当前颜色。

请注意,pgf目前不完全支持 hsb 颜色模型,您可以! Package pgf Error: Unsupported color model `hsb'. Sorry.从中获得every mark/.append style={fill=foo!80!black}

\documentclass{article}

\usepackage{pgfplots}

% Define a color series.
\definecolorseries{foo}{hsb}{step}[hsb]{0,1,1}[hsb]{.618,0,0}
\resetcolorseries{foo}

% Now use that color series in a cycle list.
\pgfplotscreateplotcyclelist{mylist}{
  % based on cycle list "color"
  {foo!![0]},every mark/.append style={fill=blue!80!black},mark=*\\
  {foo!![1]},every mark/.append style={fill=red!80!black},mark=square*\\
  {foo!![2]},every mark/.append style={fill=brown!80!black},mark=otimes*\\
  {foo!![3]},mark=star\\
  {foo!![4]},every mark/.append style={fill=blue!80!black},mark=diamond*\\
  {foo!![5]},densely dashed,every mark/.append style={solid,fill=red!80!black},mark=*\\
  {foo!![6]},densely dashed,every mark/.append style={solid,fill=brown!80!black},mark=square*\\
  {foo!![7]},densely dashed,every mark/.append style={solid,fill=gray},mark=otimes*\\
  {foo!![8]},densely dashed,mark=star,every mark/.append style=solid\\
  {foo!![9]},densely dashed,every mark/.append style={solid,fill=red!80!black},mark=diamond*\\
}

\begin{document}

For testing and checking:\par
{\ttfamily
  \foreach \i in {0,1,...,4} { \textcolor{foo!!+}{foo!![\i]} }\par
  \foreach \i in {5,6,...,9} { \textcolor{foo!!+}{foo!![\i]} }
}

\resetcolorseries{foo}

\begin{tikzpicture}
  \begin{axis} [
        stack plots=y,
        stack dir=minus,
        cycle list name=mylist,
      ]
    \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}

在此处输入图片描述

相关内容