2

I need to draw these two graphs using LaTeX, but so far I have no sucess.

enter image description here

enter image description here

This is the closest I got to the first one (for the second one I have no MWE unfortunately)

 \documentclass[14pt]{extarticle}

  \usepackage[margin=1in]{geometry} 
  \usepackage{etoolbox}
  \usepackage{tikz}
  \usetikzlibrary{calc,patterns,angles,quotes}
  \usetikzlibrary{through,arrows,shapes,trees,positioning}
  \usepackage{pgfplots}
  \usepackage{accents}
  \pgfplotsset{width=7cm,compat=newest}
  \usepackage{accents}
  \usepackage{calc}
  \usepackage{pst-node}
  \makeatletter
\pgfplotsset{
/tikz/max node/.style={
    anchor=south
},
/tikz/min node/.style={
    anchor=north
},
mark min/.style={
    point meta rel=per plot,
    visualization depends on={x \as \xvalue},
    scatter/@pre marker code/.code={%
        \ifx\pgfplotspointmeta\pgfplots@metamin
            \def\markopts{}%
            \node [min node] {
                \pgfmathprintnumber[fixed]{\xvalue},%
                \pgfmathprintnumber[fixed]{\pgfplotspointmeta}
            };
        \else
            \def\markopts{mark=none}
        \fi
        \expandafter\scope\expandafter[\markopts,every node near coord/.style=green]
    },%
    scatter/@post marker code/.code={%
        \endscope
    },
    scatter,
},
mark max/.style={
    point meta rel=per plot,
    visualization depends on={x \as \xvalue},
    scatter/@pre marker code/.code={%
    \ifx\pgfplotspointmeta\pgfplots@metamax
        \def\markopts{}%
        \node [max node] {
            \pgfmathprintnumber[fixed]{\xvalue},%
            \pgfmathprintnumber[fixed]{\pgfplotspointmeta}
        };
    \else
        \def\markopts{mark=none}
    \fi
        \expandafter\scope\expandafter[\markopts]
    },%
    scatter/@post marker code/.code={%
        \endscope
    },
    scatter
}
}
\makeatother


  \begin{document}
  \begin{tikzpicture}
  \begin{axis}[
  xlabel=$$,
  ylabel=$$
  ]
  \addplot[mark min, every node near coord/.style=] {sin(deg(x))};
  \end{axis}
  \end{tikzpicture}

  \end{document}

Thank you in advance

  • Your snippet is not exactly a MWE... what are the use of pst-node and most of tikz libraries in this case ? Also, mark min does not seem to be a default tikz or pgfplots style, which makes your snippet not compilable. Could you please update it ? – BambOo Apr 30 '18 at 20:21
  • @BambOo I just updated the question. Hope it works now – user151562 Apr 30 '18 at 20:29
7
\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\tikzset{declare function={f(\x)=2+1.2*sin(deg(\x))+0.3*\x;}}
\begin{tikzpicture}
 \draw[-latex](0,0) -- (8,0) node[below]{$x$};
 \draw[-latex](0,0) -- (0,5) node[left]{$y$};
 \draw plot[domain=0:6,variable=\x,samples=100] ({\x+1},{f(\x)});
 \foreach \X in {1,...,6}
 {\draw[dashed] ({\X},0) -- ({\X},{f(\X-1)+0.2});
 \node[circle,draw,fill,label=above:$f_\X$,scale=0.3] at ({\X+0.5},{f(\X-0.5)}){}; 
 }
 \draw[dashed] (7,0) -- (7,{f(6)+0.2});
 \draw(1,0.2) -- (1,-0.2) node[below]{$a$};
 \draw(7,0.2) -- (7,-0.2) node[below]{$b$};
\end{tikzpicture}
\tikzset{declare function={g(\x)=0.6+0.4*sin(deg(\x))+0.15*\x;}}
\begin{tikzpicture}
 \draw[-latex](0,0) -- (8,0) node[below]{$x$};
 \draw[-latex](0,0) -- (0,5) node[left]{$y$};
 \draw plot[domain=0:6,variable=\x,samples=100] ({\x+1},{f(\x)});
 \draw plot[domain=0:6,variable=\x,samples=100] ({\x+1},{g(\x)});
 \foreach \X in {1,...,6}
 {\draw[dashed] ({\X},0) -- ({\X},{f(\X-1)+0.2});
 \node[circle,draw,fill,label=above:$f_\X$,scale=0.3] at ({\X+0.5},{f(\X-0.5)}){}; 
 \node[circle,draw,fill,label=below:$g_\X$,scale=0.3] at ({\X+0.5},{g(\X-0.5)}){}; 
 }
 \draw[dashed] (7,0) -- (7,{f(6)+0.2});
 \draw(1,0.2) -- (1,-0.2) node[below]{$a$};
 \draw(7,0.2) -- (7,-0.2) node[below]{$b$};
\end{tikzpicture}
\end{document}

enter image description here

  • Wow!!! That worked perfectly!! Thank you @marmot!!! – user151562 Apr 30 '18 at 20:56

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.