3

I am trying to draw the following graph, but I failed to achieve it.

enter image description here

What is wrong with this code

\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{verbatim}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{calc, backgrounds}
\begin{document}
\begin{frame}[t]
\frametitle{}
\begin{tikzpicture}[scale=.9, transform shape]
\pgfmathsetmacro{\incrmnty}{.86}
\pgfmathsetmacro{\incrmntx}{.86}
\draw [thick](0,0) -- (\incrmntx*10,0);
\draw [thick](0,0) -- (0,\incrmnty*10);
\foreach \y [evaluate=\y as \aff using int(\y*10)]in {0,2,4,...,10}{ \draw [black] (0,\incrmnty*\y) node [left, xshift=-.1cm] {\aff} -- +(180:.12);}
\foreach \x [evaluate=\x as \aff using int(\x*10)]in {0,2,4,...,10}{ \draw [black] (\incrmnty*\x,0) node [below, yshift=-.25cm] {\aff} -- +(-90:\incrmntx*.2);}
\draw [very thick, blue, looseness=.9] (0,0) to [out=15, in=-110] node [pos=.0] (ao) {} node [pos=.08] (aw){} node [pos=.146] (ah) {} node [pos=.24] (af) {} node [pos=.306] (av) {} node [pos=.4] (ax) {} node [pos=.484] (as) {} node [pos=.58] (ag) {} node [pos=.704] (an) {} node [pos=.8] (at) {} node [pos=1.] (aa) {} (\incrmntx*10,\incrmnty*10);
\draw [very thick, red!70!black, looseness=1] (0,0) -- (\incrmntx*10,\incrmnty*10);
\path[clip] (0,0)  to [out=15, in=-110] (\incrmntx*10,\incrmnty*10);
\begin{scope}[on background layer]
\draw [thick, black!80!white, fill=black!65!white] (aa.center) node [black, xshift=.36cm, yshift=-3.cm] {} |- (aa.center|-0,0) -- (0,0) --  (aa.center);
\draw [thick, black!80!white, fill=black!60!white] (at.center) node [black, xshift=.36cm, yshift=-3.cm] {$\bf A_10$} |- (at.center|-0,0) -- (0,0) --  (at.center) -| (at.center-|0,0);
\draw [thick, black!80!white, fill=black!55!white] (an.center) node [black, xshift=.28cm, yshift=-2.4cm] {$\bf A_9$} |- (an.center|-0,0) -- (0,0) --  (an.center) -| (an.center-|0,0);
\draw [thick, black!80!white, fill=black!50!white] (ag.center) node [black, xshift=.28cm, yshift=-2.cm] {$\bf A_8$} |- (ag.center|-0,0) -- (0,0) --  (ag.center) -| (ag.center-|0,0);
\draw [thick, black!80!white, fill=black!45!white] (as.center) node [black, xshift=.28cm, yshift=-1.46cm] {$\bf A_7$} |- (as.center|-0,0) -- (0,0) --  (as.center) -| (as.center-|0,0);
\draw [thick, black!80!white, fill=black!40!white] (ax.center) node [black, xshift=.28cm, yshift=-1.2cm] {$\bf A_6$} |- (ax.center|-0,0)-- (0,0) --   (ax.center) -| (ax.center-|0,0);
\draw [thick, black!80!white, fill=black!35!white] (av.center) node [black, xshift=.28cm, yshift=-.9cm] {$\bf A_5$} |- (av.center|-0,0) -- (0,0) --  (av.center) -| (av.center-|0,0);
\draw [thick, black!80!white, fill=black!30!white] (af.center) node [black, xshift=.28cm, yshift=-.68cm] {$\bf A_4$} |- (af.center|-0,0)-- (0,0) --   (af.center) -| (af.center-|0,0);
\draw [thick, black!80!white, fill=black!25!white] (ah.center) node [black, xshift=.28cm, yshift=-.4cm] {$\bf A_3$} |- (ah.center|-0,0) -- (0,0) --  (ah.center) -| (ah.center-|0,0);
\draw [thick, black!80!white, fill=black!20!white] (aw.center) node [black, xshift=.28cm, yshift=-.16cm] {$\bf A_2$} |- (aw.center|-0,0) -- (0,0) -- (aw.center) -| (aw.center-|0,0);
\draw [thick, black!80!white, fill=black!20!white] (ao.center) node [black, xshift=.8cm, yshift=0cm] {$\bf A_1$} |- (ao.center|-0,0) -- (0,0) -- (ao.center) -| (ao.center-|0,0);
\end{scope}
\end{tikzpicture}
\end{frame}
\end{document}

It generated the following drawing

enter image description here

The following comments should be fulfilled

  1. the shaded areas should be confined below the blue curve, to the x-axis.

  2. there should be no line connecting the nodes on the blue curve with position (0,0).

  3. the relations to y60 and y20 are not correct.

4

Similar to Martin Scharrer's nice answer but with loops to make the code shorter. (And yes, the looseness was missing in the clip path.)

\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{verbatim}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{frame}[t]
\frametitle{}
\begin{tikzpicture}[scale=.9, transform shape]
\pgfmathsetmacro{\incrmnty}{.86}
\pgfmathsetmacro{\incrmntx}{.86}
\draw [thick](0,0) -- (\incrmntx*10,0);
\draw [thick](0,0) -- (0,\incrmnty*10);
\foreach \y [evaluate=\y as \aff using int(\y*10)]in {0,2,4,...,10}
{ \draw [black] (0,\incrmnty*\y) node [left, xshift=-.1cm] {\aff} -- +(180:.12);}
\foreach \x [evaluate=\x as \aff using int(\x*10)]in {0,2,4,...,10}
{ \draw [black] (\incrmnty*\x,0) node [below, yshift=-.25cm] {\aff} -- +(-90:\incrmntx*.2);}
\draw [very thick, blue] (0,0) to [out=15, in=-110, looseness=.9] 
coordinate [pos=.0] (ao)  coordinate [pos=.08] (aw) coordinate [pos=.146] (ah)  
coordinate [pos=.24] (af)  coordinate [pos=.306] (av)  coordinate [pos=.4] (ax)  
coordinate [pos=.484] (as)  coordinate [pos=.58] (ag)  coordinate [pos=.704] (an)  
coordinate [pos=.8] (at)  coordinate [pos=1.] (aa)  (\incrmntx*10,\incrmnty*10);
\draw [very thick, red!70!black, looseness=1] (0,0) -- (\incrmntx*10,\incrmnty*10);
\begin{scope}[on background layer]
\path[clip,postaction={draw,green,line width=1mm}] (0,0)  
to [out=15, in=-110, looseness=.9] (\incrmntx*10,\incrmnty*10) |- cycle;
\foreach \X [count=\Y,evaluate=\Y as \Z using {int(12-\Y)}] in {aa,at,an,ag,as,ax,av,af,ah,aw,ao}
{\pgfmathtruncatemacro{\fullness}{70-5*\Y}
\draw [thick, black!80!white, fill=black!\fullness!white]
(0,0) -- (\X.center) |-  cycle ;}
\end{scope}
\foreach \X [count=\Y,evaluate=\Y as \Z using {int(11-\Y)}] in {at,an,ag,as,ax,av,af,ah,aw,ao}
\draw [thick] (\X.center|-0,0) |- (\X.center-| (0,0)node[pos=0.25,right]{$\boldsymbol{A_{\Z}}$};
\end{tikzpicture}
\end{frame}
\end{document}

enter image description here

| improve this answer | |
  • Thank you all very very much. Both (Martin Scharrer/marmot) and (AndréC) codes gave me what I was looking for. – Hany Feb 7 '19 at 8:06
7

You need to place the clipping path into the scope, not before it, and close the clipping path with e.g. |- cycle or similar. Also you should need the same parameters as with the actual line. The looseness value was missing.

This solves points 1 and 2 of your list. I don't understand what you mean with point 3.

I also fixed your A_10 which needs to be written as A_{10}.

\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{verbatim}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{calc, backgrounds}
\begin{document}
\begin{frame}[t]
\frametitle{}
\begin{tikzpicture}[scale=.9, transform shape]
\pgfmathsetmacro{\incrmnty}{.86}
\pgfmathsetmacro{\incrmntx}{.86}

\draw [thick](0,0) -- (\incrmntx*10,0);
\draw [thick](0,0) -- (0,\incrmnty*10);

\foreach \y [evaluate=\y as \aff using int(\y*10)] in {0,2,4,...,10}{
    \draw [black] (0,\incrmnty*\y) node [left, xshift=-.1cm] {\aff} -- +(180:.12);
}

\foreach \x [evaluate=\x as \aff using int(\x*10)] in {0,2,4,...,10}{
    \draw [black] (\incrmnty*\x,0) node [below, yshift=-.25cm] {\aff} -- +(-90:\incrmntx*.2);
}

\draw [very thick, blue, looseness=.9] (0,0) to [out=15, in=-110] 
    node [pos=.0] (ao) {}
    node [pos=.08] (aw){}
    node [pos=.146] (ah) {}
    node [pos=.24] (af) {}
    node [pos=.306] (av) {}
    node [pos=.4] (ax) {}
    node [pos=.484] (as) {}
    node [pos=.58] (ag) {}
    node [pos=.704] (an) {}
    node [pos=.8] (at) {}
    node [pos=1.] (aa) {}
    (\incrmntx*10,\incrmnty*10);

\draw [very thick, red!70!black, looseness=1] (0,0) -- (\incrmntx*10,\incrmnty*10);
\begin{scope}[on background layer]
\path [clip, looseness=.9] (0,0) to [out=15, in=-110] (\incrmntx*10,\incrmnty*10) |- (0, -1) -- cycle;
\draw [thick, black!80!white, fill=green!65!white] (aa.center) node [black, xshift=.36cm, yshift=-3.cm] {X} |- (aa.center|-0,0) -- (0,0) --  (aa.center);
\draw [thick, black!80!white, fill=black!60!white] (at.center) node [black, xshift=.36cm, yshift=-3.cm] {$\bf A_{10}$} |- (at.center|-0,0) -- (0,0) --  (at.center) -| (at.center-|0,0);
\draw [thick, black!80!white, fill=black!55!white] (an.center) node [black, xshift=.28cm, yshift=-2.4cm] {$\bf A_9$} |- (an.center|-0,0) -- (0,0) --  (an.center) -| (an.center-|0,0);
\draw [thick, black!80!white, fill=black!50!white] (ag.center) node [black, xshift=.28cm, yshift=-2.cm] {$\bf A_8$} |- (ag.center|-0,0) -- (0,0) --  (ag.center) -| (ag.center-|0,0);
\draw [thick, black!80!white, fill=black!45!white] (as.center) node [black, xshift=.28cm, yshift=-1.46cm] {$\bf A_7$} |- (as.center|-0,0) -- (0,0) --  (as.center) -| (as.center-|0,0);
\draw [thick, black!80!white, fill=black!40!white] (ax.center) node [black, xshift=.28cm, yshift=-1.2cm] {$\bf A_6$} |- (ax.center|-0,0)-- (0,0) --   (ax.center) -| (ax.center-|0,0);
\draw [thick, black!80!white, fill=black!35!white] (av.center) node [black, xshift=.28cm, yshift=-.9cm] {$\bf A_5$} |- (av.center|-0,0) -- (0,0) --  (av.center) -| (av.center-|0,0);
\draw [thick, black!80!white, fill=black!30!white] (af.center) node [black, xshift=.28cm, yshift=-.68cm] {$\bf A_4$} |- (af.center|-0,0)-- (0,0) --   (af.center) -| (af.center-|0,0);
\draw [thick, black!80!white, fill=black!25!white] (ah.center) node [black, xshift=.28cm, yshift=-.4cm] {$\bf A_3$} |- (ah.center|-0,0) -- (0,0) --  (ah.center) -| (ah.center-|0,0);
\draw [thick, black!80!white, fill=black!20!white] (aw.center) node [black, xshift=.28cm, yshift=-.16cm] {$\bf A_2$} |- (aw.center|-0,0) -- (0,0) -- (aw.center) -| (aw.center-|0,0);
\draw [thick, black!80!white, fill=black!20!white] (ao.center) node [black, xshift=.8cm, yshift=0cm] {$\bf A_1$} |- (ao.center|-0,0) -- (0,0) -- (ao.center) -| (ao.center-|0,0);
\end{scope}
\end{tikzpicture}
\end{frame}
\end{document}

enter image description here

| improve this answer | |
  • Thank you very much for your answer. I was confused which to accept as an answer; but marmot`s code was shorter. – Hany Feb 7 '19 at 8:10
3

I have to go to work, I will come back this afternoon to explain the code if you need it. Sorry.

\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{verbatim}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{calc, backgrounds}
\begin{document}
\begin{frame}[t]
\frametitle{}
\begin{tikzpicture}[scale=.9, transform shape]
\pgfmathsetmacro{\incrmnty}{.86}
\pgfmathsetmacro{\incrmntx}{.86}
\draw [thick](0,0) -- (\incrmntx*10,0);
\draw [thick](0,0) -- (0,\incrmnty*10);
\foreach \y [evaluate=\y as \aff using int(\y*10)]in {0,2,4,...,10}{ \draw [black] (0,\incrmnty*\y) node [left, xshift=-.1cm] {\aff} -- +(180:.12);}
\foreach \x [evaluate=\x as \aff using int(\x*10)]in {0,2,4,...,10}{
            \draw [black] (\incrmnty*\x,0) node [below, yshift=-.25cm] {\aff} -- +(-90:\incrmntx*.2);
            }
            \draw [very thick, blue, looseness=.9] (0,0) to [out=15, in=-110] node [pos=.0] (ao) {} node [pos=.08] (aw){} node [pos=.146] (ah) {} node [pos=.24] (af) {} node [pos=.306] (av) {} node [pos=.4] (ax) {} node [pos=.484] (as) {} node [pos=.58] (ag) {} node [pos=.704] (an) {} node [pos=.8] (at) {at} node [pos=1.] (aa) {} (\incrmntx*10,\incrmnty*10);
            \draw [very thick, red!70!black, looseness=1] (0,0) -- (\incrmntx*10,\incrmnty*10);
            \path[clip] (0,0)  to [out=15, in=-110] (\incrmntx*10,\incrmnty*10);
\begin{scope}[on background layer]
\draw [thick, black!80!white, fill=black!65!white] (aa.center |- 0,0)--(aa.center)  --(at.center) |- (at.center |- 0,0) -- cycle;
\draw [thick, black!80!white, fill=black!60!white] (at.center) node [black, xshift=.36cm, yshift=-3.cm] {$\bf A_10$} --(an.center) |-(at.center |- 0,0) --cycle;
\draw [thick, black!80!white, fill=black!55!white] (an.center) node [black, xshift=.28cm, yshift=-2.4cm] {$\bf A_9$} -- (ag.center)|- (an.center|- 0,0) -- cycle;
\draw [thick, black!80!white, fill=black!50!white] (ag.center) node [black, xshift=.28cm, yshift=-2.cm] {$\bf A_8$} --(as.center) |- (ag.center|-0,0) -- cycle;
\draw [thick, black!80!white, fill=black!45!white] (as.center) node [black, xshift=.28cm, yshift=-1.46cm] {$\bf A_7$} --(ax.center)|- (as.center|-0,0) -- cycle;
\draw [thick, black!80!white, fill=black!40!white] (ax.center) node [black, xshift=.28cm, yshift=-1.2cm] {$\bf A_6$} -- (av.center)|- (ax.center|-0,0)-- cycle;
\draw [thick, black!80!white, fill=black!35!white] (av.center) node [black, xshift=.28cm, yshift=-.9cm] {$\bf A_5$} --(af.center)|- (av.center|-0,0) -- cycle;
\draw [thick, black!80!white, fill=black!30!white] (af.center) node [black, xshift=.28cm, yshift=-.68cm] {$\bf A_4$} --(ah.center)|- (af.center|-0,0)-- cycle;
\draw [thick, black!80!white, fill=black!25!white] (ah.center) node [black, xshift=.28cm, yshift=-.4cm] {$\bf A_3$} --(aw.center)|- (ah.center|-0,0) -- cycle;
\draw [thick, black!80!white, fill=black!20!white] (aw.center) node [black, xshift=.28cm, yshift=-.16cm] {$\bf A_2$} --(ao.center)|- (aw.center|-0,0) -- cycle;
%\draw [thick, black!80!white, fill=black!20!white] (ao.center) node [black, xshift=.8cm, yshift=0cm] {$\bf A_1$} |- (ao.center|-0,0) -- (0,0) -- (ao.center) -| (ao.center-|0,0);
\end{scope}
\end{tikzpicture}
\end{frame}
\end{document}

screenshot

| improve this answer | |
  • Thank you very much for your answer. Both your code and marmots are working fine. I was confused which to accept as an answer; but marmots code was shorter. – Hany Feb 7 '19 at 8:09
  • @Hany It is preferable to accept answers whose code is understood. Not for aesthetic reasons. – AndréC Feb 7 '19 at 13:12
  • Thank you AndréC for your answer. I agree with you. Your code is simpler and more understood. Both your answer and marmot`s answer are very good; and I was very confused which one to accept as an answer and which one as useful. I hope that the administrators can find a way to accept 2 answers. N.B. I added the next line for each node to draw the horizontal lines (\draw [thick, black!40!white] (at.center) -| (at.center-|0,0);) which you did not mention, but I figured it out. Again thank you very much for your effort and time. I learned very much from your answers to my previous questions. – Hany Feb 7 '19 at 18:28
  • @Hany You have not fully understood how this site works. You can wait several days before accepting an answer. And this is recommended by tex.stackexchange. This allows you to analyze each answer calmly, to ask for additional explanations. Take the time to analyze the answers. In addition, it allows others to answer later and ensures that your answer has been read by more people. – AndréC Feb 7 '19 at 18:57
  • Let me see. You have the 0 of the 10 in A_{10} displaced, an undesired at floating around, no explanation whatsoever, no attempt to shorten the code. Is this why you feel your answer is better than the others? – user121799 Feb 7 '19 at 21:27

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.