我目前正在尝试更改维恩图中两个圆之间的交叉点的颜色。我尝试了堆栈上提出的不同解决方案,但没有成功。我正在运行的代码如下;
\begin{center}
\usetikzlibrary{shapes,backgrounds}
\pagestyle{empty}
\def\firstcircle{(0,0) circle (1.5cm)}
\def\secondcircle{(60:2cm) circle (1.5cm)}
\def\thirdcircle{(0:2cm) circle (1.5cm)}
\begin{tikzpicture}
\begin{scope}[shift={(3cm,-5cm)}, fill opacity=0.5]
\fill[green] \firstcircle;
\fill[green] \secondcircle;
\fill[red] \thirdcircle;
\draw \firstcircle node[below] {$A$};
\draw \secondcircle node [above] {$B$};
\draw \thirdcircle node [below] {$C$};
\end{scope}
\end{tikzpicture}
\end{center}
答案1
fill opacity=.5
已经用不同的颜色填充了所有交叉点。但如果这对您来说还不够,并且您更喜欢为每个交叉点选择颜色,则可以使用以下代码:
\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{positioning}
\usetikzlibrary{shapes,backgrounds}
\begin{document}
\def\firstcircle{(0,0) circle (1.5cm)}
\def\secondcircle{(60:2cm) circle (1.5cm)}
\def\thirdcircle{(0:2cm) circle (1.5cm)}
\begin{tikzpicture}
\begin{scope}[shift={(3cm,-5cm)}, fill opacity=1]
\fill[green] \firstcircle node[black] {$A$};
\fill[blue] \secondcircle node[black] {$B$};
\fill[red] \thirdcircle node[black] {$C$};
\begin{scope}
\clip \firstcircle;
\fill[brown] \secondcircle;
\fill[cyan] \thirdcircle;
\end{scope}
\begin{scope}
\clip \secondcircle;
\fill[orange] \thirdcircle;
\clip \firstcircle;
\fill[pink] \thirdcircle;
\end{scope}
\end{scope}
\end{tikzpicture}
\end{document}
答案2
这里有一个元帖子版本,以便在您等待 TikZ 山地救援队时提供一些消遣。编译以lualatex
获得mplib
支持(或弄清楚如何将其改编为良好生产规范)。
\RequirePackage{luatex85}
\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);
path C[];
C1 = fullcircle rotated -60 scaled 3cm;
C2 = C1 shifted (2cm, 0);
C3 = C2 rotated 60;
path r[];
r1 = buildcycle(C1, C2);
r2 = buildcycle(C2, C3);
r3 = buildcycle(C3, C1);
r4 = buildcycle(C1, C2, C3);
fill C1 withcolor 3/4[red, white];
fill C2 withcolor 3/4[green, white];
fill C3 withcolor 3/4[blue, white];
fill r1 withcolor 3/4[red+green,white];
fill r2 withcolor 3/4[green+blue,white];
fill r3 withcolor 3/4[blue+red,white];
fill r4 withcolor 3/4[red+green+blue, white];
draw C1; label("A", center C1);
draw C2; label("B", center C2);
draw C3; label("C", center C3);
endfig;
\end{mplibcode}
\end{document}
注意:rotated -60
C1 定义中的 很重要。它阻止point 0
每个圆的 包含在其他圆中。这是避免 特征所必需的buildcycle
。