5

How to fill area between curve defined by series of control points and x-axis?

MWE:

    \documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{intersections}
\usetikzlibrary{calc}

\begin{document}

\begin{tikzpicture}
    \def\xmin{-30}
    \def\xmax{450}
    \def\ymin{-30}
    \def\ymax{150}
    \def\nula{55}
    \def\phase{2.2}
    \def\myscale{0.5}

        \begin{scope}[draw=black,line join=round,miter limit=4.00,line width=0.5pt, y=1pt,x=1pt, scale=\myscale]      
          \draw[->] (\xmin,\nula) -- (\xmax,\nula) node[right] {$t$} coordinate(x axis);
          \draw[->] (\phase,\ymin) -- (\phase,\ymax) node[left]  {$v(t)$} coordinate(y axis);
          \path[name path=fce1,draw=black,line join=round,even odd rule,line cap=butt,miter   
            limit=4.00] (2.2036044,23.21323707) .. controls
            (2.2036044,23.21323707)  and (7.1896734,29.00183707)  .. (11.896862,37.80963707)  .. controls
            (14.463984,42.61313707)  and (16.430404,45.91313707)  .. (19.958399,53.79007707)  .. controls
            (23.178819,60.98027707)  and (34.001913,68.16119707)  .. (44.701755,69.73912707)  .. controls
            (55.401595,71.31705707)  and (62.430335,112.41315707) .. (84.285711,112.14281707) .. controls
            (106.14109,111.87247707) and (131.61574,2.01243707)   .. (164.28572,1.78563707)   .. controls
            (196.9557,1.55883707)    and (217.37186,52.05023707)  .. (217.37186,52.05023707);    
        \end{scope} 
\end{tikzpicture}
\end{document}

I would like to fill the space between the x axis and the positive part of the curve (between two zero-crossing). I found a lot of examples, but I have not found in any convenient way. Therefore, I turn to the community for some advice.

5

Here are two ways with \MyPath representing your original path

  1. Add begin and end points to your path that end on the x-axis:

    \draw (\phase,\nula) -- \MyPath -- (217.37186,\nula)
    

    Everything is done in one step this way. However this method yields and additional draws which are probably not desired.

  2. First fill the region, and then draw it:

      \fill [fill=yellow!10] (\phase,\nula) -- \MyPath -- (217.37186,\nula);
      \draw \MyPath;
    

    which yields:

    enter image description here

    I would recommend method #2.

Code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{intersections}
\usetikzlibrary{calc}

\newcommand{\MyPath}{%
            (2.2036044,23.21323707) .. controls
            (2.2036044,23.21323707)  and (7.1896734,29.00183707)  .. 
            (11.896862,37.80963707)  .. controls
            (14.463984,42.61313707)  and (16.430404,45.91313707)  .. 
            (19.958399,53.79007707)  .. controls
            (23.178819,60.98027707)  and (34.001913,68.16119707)  .. 
            (44.701755,69.73912707)  .. controls
            (55.401595,71.31705707)  and (62.430335,112.41315707) .. 
            (84.285711,112.14281707) .. controls
            (106.14109,111.87247707) and (131.61574,2.01243707)   .. 
            (164.28572,1.78563707)   .. controls
            (196.9557,1.55883707)    and (217.37186,52.05023707)  .. 
            (217.37186,52.05023707)
}%

\begin{document}

\def\xmin{-30}
\def\xmax{450}
\def\ymin{-30}
\def\ymax{150}
\def\nula{55}
\def\phase{2.2}
\def\myscale{0.5}


\begin{tikzpicture}
        \begin{scope}[draw=black,line join=round,miter limit=4.00,line width=0.5pt, y=1pt,x=1pt, scale=\myscale]      

          \path[fill=yellow!10, name path=fce1,draw=black,line join=round,even odd rule,line cap=butt,miter   
            limit=4.00] 
            (\phase,\nula) -- \MyPath -- (217.37186,\nula);    

          \draw[->] (\xmin,\nula) -- (\xmax,\nula) node[right] {$t$} coordinate(x axis);
          \draw[->] (\phase,\ymin) -- (\phase,\ymax) node[left]  {$v(t)$} coordinate(y axis);
        \end{scope} 
\end{tikzpicture}

\begin{tikzpicture}
        \begin{scope}[draw=black,line join=round,miter limit=4.00,line width=0.5pt, y=1pt,x=1pt, scale=\myscale]      

\fill [fill=yellow!10] (\phase,\nula) -- \MyPath -- (217.37186,\nula);
          \path[name path=fce1,draw=black,line join=round,even odd rule,line cap=butt,miter   
            limit=4.00] 
          \MyPath;    

          \draw[->] (\xmin,\nula) -- (\xmax,\nula) node[right] {$t$} coordinate(x axis);
          \draw[->] (\phase,\ymin) -- (\phase,\ymax) node[left]  {$v(t)$} coordinate(y axis);
        \end{scope} 
\end{tikzpicture}
\end{document}
\end{document}
1
  • Thank you very much. I would need to fill up began after passing through the signal zero. It is very difficult for me to modify the curve mypath so that starting from the coordinates 0,0. A similar situation occurs if I wanted to fill in only one polarity signals.
    – JardaFait
    Nov 27 '12 at 14:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.