Following your idea (I don't know pgfplots
very much), you could stack successively the positive part and the negative part of the difference of the two functions.
As the following code shows, it is not perfect, but it works. Note that I have increased the sample size in order to smooth the sign-changing parts.
\documentclass{minimal}
\usepackage{tikz,pgfplots}
\begin{document}
\tikz[scale=.6,domain=-2:2,samples=50]{
\begin{axis}[axis on top=false, axis x line=middle, axis y line=middle,stack plots=y]
% plot first function
\addplot+[mark=none] {.55*x+.13};
% substract first function from the second one, since they are stacked, and plot successively the positive and negative parts
\addplot+[mark=none,fill=red,draw=black] {max(.2*x^3-.05*x^2+.2-(.55*x+.13),0)} \closedcycle;
\addplot+[mark=none,fill=green,draw=black] {min(.2*x^3-.05*x^2+.2-(.55*x+.13),0)} \closedcycle;
\end{axis}
}
\end{document}
Something like this is made with the libraries decorations.text
and arrows.meta
together with the correspondent options
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.text,calc,arrows.meta}
\begin{document}
\begin{tikzpicture}
\coordinate (O) at (0,0);
\draw (O) circle (2.5);
\draw (O) circle (1.5);
\draw (O) circle (0.5);
\draw[decoration={text along path,reverse path,text align={align=center},text={Wee}},decorate] (0.6,0) arc (0:180:0.6);
\draw[decoration={text along path,reverse path,text align={align=center},text={There is a way?}},decorate] (1.6,0) arc (0:180:1.6);
\draw[decoration={text along path,reverse path,text align={align=center},text={Should be here any!}},decorate] (2.6,0) arc (0:180:2.6);
\begin{scope}[xshift=6cm]
\coordinate (O) at (0,0);
\draw[fill=red!30] (O) circle (2.8);
\draw[fill=green!40] (O) circle (2);
\draw[fill=yellow!70] (O) circle (1.2);
\draw[fill=blue!45] (O) circle (0.4);
\draw[decoration={text along path,reverse path,text align={align=center},text={xxx}},decorate] (0.5,0) arc (0:180:0.5);
\draw[decoration={text along path,reverse path,text align={align=center},text={yyy}},decorate] (1.3,0) arc (0:180:1.3);
%\draw[decoration={text along path,reverse path,text align={align=center},text={Should be here any!}},decorate] (2.1,0) arc (0:180:2.1);
\draw[decoration={text along path,reverse path,text align={align=center},text={Hello, how are you?}},decorate] (2.9,0) arc (0:180:2.9);
\end{scope}
\draw[line width=2mm,>={Triangle[length=3mm,width=5mm]},->] (2.6,0) -- (3.8,0);
\end{tikzpicture}
\end{document}
Result
EDIT
Or you can simplify the code a bit by using loops (\foreach
)
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.text,calc,arrows.meta}
\begin{document}
\begin{tikzpicture}
\coordinate (O) at (0,0);
\foreach \j in {1,...,3} \draw (O) circle (3.5-\j);
\foreach \k/\text in {0/Should be here any!,1/There is a way?,2/Wee} \draw[decoration={text along path,reverse path,text align={align=center},text={\text}},decorate] (2.6-\k,0) arc (0:180:2.6-\k);
\begin{scope}[xshift=6cm]
\coordinate (O) at (0,0);
\foreach \k in {1,...,4}\pgfmathparse{12*\k} \draw[fill=red!\pgfmathresult] (O) circle (3.6-0.8*\k);
\foreach \k/\text in {0/{Hello, how are you?},1/,2/yyy,3/xxx} \draw[decoration={text along path,reverse path,text align={align=center},text={\text}},decorate] (2.9-0.8*\k,0) arc (0:180:2.9-0.8*\k);
\end{scope}
\draw[line width=2mm,>={Triangle[length=3mm,width=5mm]},->] (2.6,0) -- (3.8,0);
\end{tikzpicture}
\end{document}
Best Answer
You can use the
even odd rule
for filling. The red line is just to show the inner circle is transparent.