背景颜色混合

背景颜色混合

我制作了下图

在此处输入图片描述

代码如下

\documentclass[tikz]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{mathtools}
\usepackage{bm}
\usepackage{stmaryrd}
\pgfplotsset{compat=1.12}
\usetikzlibrary{arrows,petri,backgrounds}
\tikzset{>=stealth',every on chain/.append style={join}, every join/.style={->}}
\begin{document}
\begin{tikzpicture}[thick,auto,node distance=58pt]
    \tikzstyle{n}=[circle,draw=blue!75,fill=blue!20,minimum size=10pt,inner sep=0pt]
    \tikzstyle{pil}=[->,thick,shorten <=2pt,shorten >=2pt]

    \node [n] (css) [label=above:$c$] {};
    \node [n] (ss) [label=left:$\text{SelectedStudy}(\texttt{s}_i)$, below of=css,
    yshift=20pt,tokens=1] {};
    \node [n] (and1) [label=above left:$\texttt{AND}$, below left of=ss, tokens=1] {};
    \node [n] (and2) [label=above right:$\texttt{AND}$, below right of=ss, tokens=1] {};
    \node [n] (tis) [label=below:{$\text{TermInStudy}(\texttt{t}_j, \texttt{s}_i)$}, left of=and1, tokens=1] {};
    \node [n] (vr) [label=below:{$\text{VoxelReported}(\texttt{v}_k, \texttt{s}_i)$}, right of=and2, tokens=1] {};
    \node [n] (ctis) [label=above:$c_{ji}$, left of=tis] {};
    \node [n] (cvr) [label=above:$c_{ki}$, right of=vr] {};
    \node [n] (ta) [label=left:$\text{TermAssociation}(\texttt{t}_j)$, below of=and1] {};
    \node [n] (a) [label=right:$\text{Activation}(\texttt{v}_k)$, below of=and2] {};

    \node (whatever1) [below of=cvr,yshift=30pt] {};
    \node (whatever2) [above of=cvr,yshift=-13pt,xshift=-5pt] {$i \in N$};
    \node (whatever3) [above of=ctis,yshift=-45pt] {};
    \node (whatever4) [above of=cvr,yshift=-45pt] {};

    \node (whatever5) [right of=a,xshift=50pt] {$k \in K$};
    \node (whatever6) [left of=ta,xshift=-50pt] {$j \in M$};

    \node [n] (whatever7) [opacity=0.6, left of=css,xshift=-80pt,tokens=1,label=right:{\scriptsize%
        deterministic CPD}] {};


    \path[pil] (css) edge (ss);
    \path[pil] (ss) edge (and1);
    \path[pil] (ss) edge (and2);
    \path[pil] (ctis) edge (tis);
    \path[pil] (tis) edge (and1);
    \path[pil] (cvr) edge (vr);
    \path[pil] (vr) edge (and2);
    \path[pil] (and1) edge (ta);
    \path[pil] (and2) edge (a);

    \begin{scope}[blend group = soft light]
        \begin{pgfonlayer}{background}
            \filldraw [line width=20pt,join=round,yellow!20!white]
            (ss.north  -| ctis.west)  rectangle (whatever1.south  -| cvr.east);
        \end{pgfonlayer}

        \begin{pgfonlayer}{background}
            \filldraw [line width=10pt,join=round,green!20!white]
            (whatever3.north  -| ctis.west)  rectangle (ta.south  -| ta.east);
        \end{pgfonlayer}

        \begin{pgfonlayer}{background}
            \filldraw [line width=10pt,join=round,red!15!white]
            (whatever4.north  -| and2.west)  rectangle (a.south  -| cvr.east);
        \end{pgfonlayer}
    \end{scope}

\end{tikzpicture}

\end{document}

我希望颜色能够像下面从 tikz 示例中获取的图像那样混合(http://www.texample.net/tikz/examples/venn/

在此处输入图片描述

我怎样才能做到这一点?

答案1

很难知道你到底想要什么效果,说实话我觉得混合模式是一种黑魔法……但这有一个想法。

有几件事您需要修复。

首先,将背景层放在混合透明度范围内是行不通的。因此,将其移到外面,这样透明度范围内就只有三个矩形了。

其次,使用粗线,虽然是一种获得更大边框的巧妙方法,但是会填满混合,因为您会在填充顶部绘制线条。

第三,示例维恩图中选择的混合模式对于按该顺序绘制的颜色效果很好。但对于您选择的颜色效果就不太好了。如果您最后绘制黄色矩形,看起来就没问题。或者您可能会发现混合模式multiply也适合您所追求的效果。

以下是我对混合的建议:

  \begin{pgfonlayer}{background}
    \begin{scope}[
        blend group = soft light,
        rounded corners=10pt,
        nw/.style={xshift=-10pt,yshift=10pt},
        se/.style={xshift=10pt, yshift=-10pt},
        snw/.style={xshift=-5pt,yshift=5pt},
        sse/.style={xshift=5pt, yshift=-5pt}]
      \fill [green!20!white]
        ([snw]{whatever3.north -| ctis.west}) rectangle
        ([sse]{ta.south -| ta.east});
      \fill [red!15!white]
        ([snw]{whatever4.north -| and2.west)} rectangle
        ([sse]{a.south -| cvr.east});
      \fill [yellow!20!white]
        ([nw]{ss.north -| ctis.west}) rectangle
        ([se]{whatever1.south -| cvr.east});
    \end{scope}
  \end{pgfonlayer}

得出:

柔和的灯光输出

另一种方法是使用multiply混合模式,其效果如下:

乘以输出

或者可能只是使用普通的透明度,我发现这比混合更直观:

  \begin{pgfonlayer}{background}
    \begin{scope}[
        rounded corners=10pt,
        nw/.style={xshift=-10pt,yshift=10pt},
        se/.style={xshift=10pt, yshift=-10pt},
        snw/.style={xshift=-5pt,yshift=5pt},
        sse/.style={xshift=5pt, yshift=-5pt}]
      \fill [yellow!20!white]
        ([nw]{ss.north -| ctis.west}) rectangle
        ([se]{whatever1.south -| cvr.east});
      \fill [green, opacity=0.2]
        ([snw]{whatever3.north -| ctis.west}) rectangle
        ([sse]{ta.south -| ta.east});
      \fill [red, opacity=0.15]
        ([snw]{whatever4.north -| and2.west)} rectangle
        ([sse]{a.south -| cvr.east});
    \end{scope}
  \end{pgfonlayer}

透明度输出

以下是第一个选项的完整 MWE:

\documentclass[tikz]{standalone}
\usepackage{tikz}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usetikzlibrary{arrows,petri,backgrounds}
\tikzset{>=stealth',every on chain/.append style={join}, every join/.style={->}}
\begin{document}
\begin{tikzpicture}[thick,auto,node distance=58pt]
  \tikzstyle{n}=[circle,draw=blue!75,fill=blue!20,minimum size=10pt,
    inner sep=0pt]
  \tikzstyle{pil}=[->,thick,shorten <=2pt,shorten >=2pt]
  \node [n] (css) [label=above:$c$] {};
  \node [n] (ss) [label=left:$\text{SelectedStudy}(\texttt{s}_i)$,
    below of=css, yshift=20pt,tokens=1] {};
  \node [n] (and1) [label=above left:$\texttt{AND}$,
    below left of=ss, tokens=1] {};
  \node [n] (and2) [label=above right:$\texttt{AND}$, below right of=ss, tokens=1] {};
  \node [n] (tis) [label=below:{$\text{TermInStudy}(\texttt{t}_j, \texttt{s}_i)$}, left of=and1, tokens=1] {};
  \node [n] (vr) [label=below:{$\text{VoxelReported}(\texttt{v}_k, \texttt{s}_i)$}, right of=and2, tokens=1] {};
  \node [n] (ctis) [label=above:$c_{ji}$, left of=tis] {};
  \node [n] (cvr) [label=above:$c_{ki}$, right of=vr] {};
  \node [n] (ta) [label=left:$\text{TermAssociation}(\texttt{t}_j)$, below of=and1] {};
  \node [n] (a) [label=right:$\text{Activation}(\texttt{v}_k)$, below of=and2] {};

  \node (whatever1) [below of=cvr,yshift=30pt] {};
  \node (whatever2) [above of=cvr,yshift=-13pt,xshift=-5pt] {$i \in N$};
  \node (whatever3) [above of=ctis,yshift=-45pt] {};
  \node (whatever4) [above of=cvr,yshift=-45pt] {};
  \node (whatever5) [right of=a,xshift=50pt] {$k \in K$};
  \node (whatever6) [left of=ta,xshift=-50pt] {$j \in M$};

  \node [n] (whatever7) [opacity=0.6, left of=css,xshift=-80pt, tokens=1,
    label=right:{\scriptsize deterministic CPD}] {};

  \path[pil] (css) edge (ss);
  \path[pil] (ss) edge (and1);
  \path[pil] (ss) edge (and2);
  \path[pil] (ctis) edge (tis);
  \path[pil] (tis) edge (and1);
  \path[pil] (cvr) edge (vr);
  \path[pil] (vr) edge (and2);
  \path[pil] (and1) edge (ta);
  \path[pil] (and2) edge (a);

  \begin{pgfonlayer}{background}
    \begin{scope}[
        blend group = soft light,
        rounded corners=10pt,
        nw/.style={xshift=-10pt,yshift=10pt},
        se/.style={xshift=10pt, yshift=-10pt},
        snw/.style={xshift=-5pt,yshift=5pt},
        sse/.style={xshift=5pt, yshift=-5pt}]
      \fill [green!20!white]
        ([snw]{whatever3.north -| ctis.west}) rectangle
        ([sse]{ta.south -| ta.east});
      \fill [red!15!white]
        ([snw]{whatever4.north -| and2.west)} rectangle
        ([sse]{a.south -| cvr.east});
      \fill [yellow!20!white]
        ([nw]{ss.north -| ctis.west}) rectangle
        ([se]{whatever1.south -| cvr.east});
    \end{scope}
  \end{pgfonlayer}
\end{tikzpicture}

\end{document}

答案2

混合组需要位于单个图层内,因此所有绘图命令都应移动到单个pgfonlayer范围内。此外,使用filldraw将混合线条和填充,这是不可取的。在这里,我在所需节点周围安装了节点以实现所需的效果。

\documentclass[tikz,border=5]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{mathtools}
\usepackage{bm}
\usepackage{stmaryrd}
\pgfplotsset{compat=1.12}
\usetikzlibrary{arrows,petri,backgrounds,fit}
\tikzset{>=stealth',every on chain/.append style={join}, every join/.style={->}}
\begin{document}
\begin{tikzpicture}[thick,auto,node distance=58pt]
    \tikzstyle{n}=[circle,draw=blue!75,fill=blue!20,minimum size=10pt,inner sep=0pt]
    \tikzstyle{pil}=[->,thick,shorten <=2pt,shorten >=2pt]

    \node [n] (css) [label=above:$c$] {};
    \node [n] (ss) [label=left:$\text{SelectedStudy}(\texttt{s}_i)$, below of=css,
    yshift=20pt,tokens=1] {};
    \node [n] (and1) [label=above left:$\texttt{AND}$, below left of=ss, tokens=1] {};
    \node [n] (and2) [label=above right:$\texttt{AND}$, below right of=ss, tokens=1] {};
    \node [n] (tis) [label=below:{$\text{TermInStudy}(\texttt{t}_j, \texttt{s}_i)$}, left of=and1, tokens=1] {};
    \node [n] (vr) [label=below:{$\text{VoxelReported}(\texttt{v}_k, \texttt{s}_i)$}, right of=and2, tokens=1] {};
    \node [n] (ctis) [label=above:$c_{ji}$, left of=tis] {};
    \node [n] (cvr) [label=above:$c_{ki}$, right of=vr] {};
    \node [n] (ta) [label=left:$\text{TermAssociation}(\texttt{t}_j)$, below of=and1] {};
    \node [n] (a) [label=right:$\text{Activation}(\texttt{v}_k)$, below of=and2] {};

    \node (whatever1) [below of=cvr,yshift=30pt] {};
    \node (whatever2) [above of=cvr,yshift=-13pt,xshift=-5pt] {$i \in N$};
    \node (whatever3) [above of=ctis,yshift=-45pt] {};
    \node (whatever4) [above of=cvr,yshift=-45pt] {};

    \node (whatever5) [right of=a,xshift=50pt] {$k \in K$};
    \node (whatever6) [left of=ta,xshift=-50pt] {$j \in M$};

    \node [n] (whatever7) [opacity=0.6, left of=css,xshift=-80pt,tokens=1,label=right:{\scriptsize%
        deterministic CPD}] {};

    \path[pil] (css) edge (ss);
    \path[pil] (ss) edge (and1);
    \path[pil] (ss) edge (and2);
    \path[pil] (ctis) edge (tis);
    \path[pil] (tis) edge (and1);
    \path[pil] (cvr) edge (vr);
    \path[pil] (vr) edge (and2);
    \path[pil] (and1) edge (ta);
    \path[pil] (and2) edge (a);

    \begin{pgfonlayer}{background}
        \begin{scope}[blend group = soft light]

        \node [fill=yellow!20!white,
               inner xsep=0.5cm,
               inner ysep=0.25cm,
               rounded corners=0.25cm,
               fit={(ss.north) (ctis.west) (whatever1.south) (cvr.east)}] {};

        \node [fill=green!20!white,
               inner sep=0.25cm,
               rounded corners=0.25cm,
               fit={(whatever3.north) (ctis.west)  (ta.south) (ta.east)}] {};

        \node [fill=red!15!white,
               inner sep=0.25cm,
               rounded corners=0.25cm,
               fit={(whatever4.north) (and2.west) (a.south) (cvr.east)}] {};
    \end{scope}
\end{pgfonlayer}
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案3

您可以使用,例如:

\fill[green!20!white, fill opacity=0.5, rounded corners=5pt]
  (a) rectangle (b);

没有绘制操作,否则边框会更暗。请注意,已\tikzstyle弃用。您应该使用positioning库来更好地定位节点。我修改了$i \in N$这种方式来向您展示,但您的示例是远非极简,所以我不会修复其他节点的放置方式(这会太长并且不会使任何人受益)。

请提供最小下次再举个例子。你为什么需要pgfplots这里的东西?!你添加的几乎所有包在这里都是没用的。

您可能需要考虑使用\operatorname而不是\text作为函数名称。

\documentclass[tikz]{standalone}
\usepackage{amsmath}
\usepackage{tikz}

\usetikzlibrary{arrows, petri, backgrounds, positioning}
\tikzset{
  >=stealth', every on chain/.append style={join}, every join/.style={->}
}

\begin{document}

\begin{tikzpicture}[
  thick, auto, node distance=58pt,
  n/.style={circle, draw=blue!75,fill=blue!20, minimum size=10pt, inner sep=0pt},
  pil/.style={->, thick,shorten <=2pt, shorten >=2pt}]

    \node [n] (css) [label=above:$c$] {};
    \node [n] (ss) [label=left:$\text{SelectedStudy}(\texttt{s}_i)$, below of=css,
    yshift=20pt,tokens=1] {};
    \node [n] (and1) [label=above left:$\texttt{AND}$, below left of=ss, tokens=1] {};
    \node [n] (and2) [label=above right:$\texttt{AND}$, below right of=ss, tokens=1] {};
    \node [n] (tis) [label=below:{$\text{TermInStudy}(\texttt{t}_j, \texttt{s}_i)$}, left of=and1, tokens=1] {};
    \node [n] (vr) [label=below:{$\text{VoxelReported}(\texttt{v}_k, \texttt{s}_i)$}, right of=and2, tokens=1] {};
    \node [n] (ctis) [label=above:$c_{ji}$, left of=tis, xshift=-10pt] {};
    \node [n] (cvr) [label=above:$c_{ki}$, right of=vr] {};
    \node [n] (ta) [label=left:$\text{TermAssociation}(\texttt{t}_j)$, below of=and1] {};
    \node [n] (a) [label=right:$\text{Activation}(\texttt{v}_k)$, below of=and2] {};

    \node (whatever1) [below of=cvr,yshift=30pt] {};
    \node (whatever2) [above left=25pt and -10pt of cvr] {$i \in N$};
    \node (whatever3) [above of=ctis,yshift=-45pt] {};
    \node (whatever4) [above of=cvr,yshift=-45pt] {};

    \node (whatever5) [right of=a,xshift=50pt] {$k \in K$};
    \node (whatever6) [left of=ta,xshift=-60pt] {$j \in M$};

    \node [n] (whatever7) [opacity=0.6, left of=css, xshift=-80pt, tokens=1,
                           label=right:{\scriptsize deterministic CPD}] {};

    \path[pil] (css) edge (ss);
    \path[pil] (ss) edge (and1);
    \path[pil] (ss) edge (and2);
    \path[pil] (ctis) edge (tis);
    \path[pil] (tis) edge (and1);
    \path[pil] (cvr) edge (vr);
    \path[pil] (vr) edge (and2);
    \path[pil] (and1) edge (ta);
    \path[pil] (and2) edge (a);

    \begin{pgfonlayer}{background}
      \fill[yellow!20!white, rounded corners=10pt]
        (ss.north  -| ctis.west)  rectangle (whatever1.south  -| cvr.east);

      \begin{scope}[rounded corners=5pt]
        \fill[green!20!white, fill opacity=0.5]
          (whatever3.north -| ctis.west) rectangle (ta.south  -| ta.east);
        \fill[red!15!white, fill opacity=0.5]
          (whatever4.north -| and2.west) rectangle (a.south  -| cvr.east);
      \end{scope}
    \end{pgfonlayer}
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容