答案1
在我的论文中,我使用类似这样的代码来表示我的模糊隶属函数。您可以轻松地将此代码应用于您的案例。为此,您需要更改用于表示函数及其填充的路径,并更改 X 轴的标签。
\documentclass[tikz]{standalone}
\usepackage{xcolor}
\definecolor{RdBu-9-1}{RGB}{178,24,43}
\definecolor{RdBu-9-2}{RGB}{214,96,77}
\definecolor{RdBu-9-3}{RGB}{244,165,130}
\definecolor{RdBu-9-4}{RGB}{253,219,199}
\definecolor{RdBu-9-5}{RGB}{247,247,247}
\definecolor{RdBu-9-6}{RGB}{209,229,240}
\definecolor{RdBu-9-7}{RGB}{146,197,222}
\definecolor{RdBu-9-8}{RGB}{67,147,195}
\definecolor{RdBu-9-9}{RGB}{33,102,172}
\usepackage{tikz}
\usetikzlibrary{patterns}
\usetikzlibrary{fadings}
% Styles
\tikzset{%
ffa/.style={%
pattern=north west lines,
pattern color=RdBu-9-2,
draw=none
},
ffa2/.style={%
pattern=north east lines,
pattern color=RdBu-9-8,
draw=none
},
ffa_fade/.style={%
ffa,
path fading=east
},
ffa_fade_m/.style={%
ffa,
path fading=west
},
ffa2_fade/.style={%
ffa2,
path fading=east
},
ffa2_fade_m/.style={%
ffa2,
path fading=west
},
ffc/.style={%
draw=RdBu-9-1,
line width=1
},
ffc2/.style={%
draw=RdBu-9-9,
line width=1
},
% Rendu ligne transparente sans apparition des patterns en dessous
ffc_fade/.style={%
ffc,
draw=white,
postaction={%
draw=RdBu-9-1,
path fading=east
}
},
ffc_fade_m/.style={%
ffc,
draw=white,
postaction={%
draw=RdBu-9-1,
path fading=west
}
},
ffc2_fade/.style={%
ffc2,
draw=white,
postaction={%
draw=RdBu-9-9,
path fading=east
}
},
ffc2_fade_m/.style={%
ffc2,
draw=white,
postaction={%
draw=RdBu-9-9,
path fading=west
}
}
}
\begin{document}
\begin{tikzpicture}
\def\decalageX{-.2}
\def\decalageY{-.2}
% functions
\begin{scope}[transparency group]
\begin{scope}
\path[ffa] (3,0) -- (3.5, 2) -- (5.5,2) -- (6,0) -- cycle;
\path[ffa2] (0,0) -- (0,2) -- (3,2) -- (3.5, 0) -- (5.5,0) --
(6,2) --(9,2) -- (9,0) -- cycle;
\end{scope}
\begin{scope}
\path[ffc] (0,0) -- (3,0) -- (3.5, 2) --(5.5,2) -- (6,0) -- (9,0) ;
\path[ffc2] (0,2) -- (3,2) -- (3.5, 0) -- (5.5,0) -- (6,2) -- (9,2) ;
\end{scope}
\end{scope}
%
% Axis
\begin{scope}
% Axis X
\begin{scope}
% Draw axis
\draw[|-|] (0, \decalageX) --++ (9, 0) coordinate (x axis);
% Add gradiations with a loop
% You can add the labels in the {}, like 2.5/{32}
\foreach \n/\t in {0.5/{},1.5/{},2.5/{},3.5/{},4.5/{},5.5/{},6.5/{},7.5/{},8.5/{}}
{
% Graduation
\draw[-] (\n, \decalageX - .05) --++ (0, .1);
% Graduation label
\node[below, font=\footnotesize] at (\n, \decalageX - .05) {\t};
}
% label of axis
\node[below left, xshift=-.4cm, yshift=-.1cm, font=\small] at (x
axis) {\itshape x value};
\end{scope}
% Axis Y
\begin{scope}
\draw[-] (\decalageY ,0) --++ (0, 2) coordinate (y axis);
% Graduations
\foreach \n/\t in {0/{0},2/{1}}
{
\draw[-] (\decalageY -.05, \n) --++ (.1, 0);
\node[left, font=\footnotesize] at (\decalageY -.05, \n) {\t};
}
% Label
\node[above] at (y axis) {$\mu$};
\end{scope}
\end{scope}
\begin{scope}
% B1
\draw[ffc,line width=.5] (3,\decalageY) -- (3,0);
\draw[fill, RdBu-9-1] (3,\decalageY) circle (2pt);
\draw[fill, RdBu-9-1] (3,0) circle (2pt);
\node[below] at (3,\decalageY) {\(b1\)};
% B2
\draw[ffc,line width=.5] (3.5,\decalageY) -- (3.5,2);
\draw[fill, RdBu-9-1] (3.5,\decalageY) circle (2pt);
\draw[fill, RdBu-9-1] (3.5,2) circle (2pt);
\node[above] at (3.5,2) {\(b2\)};
% B3
\draw[ffc,line width=.5] (5.5,\decalageY) -- (5.5,2);
\draw[fill, RdBu-9-1] (5.5,\decalageY) circle (2pt);
\draw[fill, RdBu-9-1] (5.5,2) circle (2pt);
\node[above] at (5.5,2) {\(b3\)};
% B4
\draw[ffc,line width=.5] (6,\decalageY) -- (6,0);
\draw[fill, RdBu-9-1] (6,\decalageY) circle (2pt);
\draw[fill, RdBu-9-1] (6,0) circle (2pt);
\node[below] at (6,\decalageY) {\(b4\)};
\end{scope}
\end{tikzpicture}
\end{document}