I'm trying to reproduce this illustration I've made in Inkscape as a tikzpictures for use in LaTex. I've looked a lot at this, and around, but I'm stuck and it's late. Would one of you kind experts out there help me figure out how to make this illustration? enter image description here

I also looked at this and this, I'll update if I work out some solution that works. IN the meantime please come in here with any suggestions of ideas. Thanks a lot!

Here's a first jab at a compilable MWE,


    integral segments/.code={\pgfmathsetmacro\integralsegments{#1}},
    integral segments=3,
    integral/.style args={#1:#2}{
        ybar interval,
        x filter/.code=\pgfmathparse{\pgfmathresult-((#2-#1)/\integralsegments)/2}

\begin{tikzpicture}[/pgf/declare function={f=-15*(x-5)+(x-5)^3+50;}] 
    axis lines=middle
\addplot [thick] {f} node[pos=1] (f) {};
\addplot [
] {f};



@salim-bou and @zarko, I'm amazed, and truly grateful you took the time, and that it didn't take you more then some minutes. Would it be too much to ask how I overlay some text on my graph (obviously not the LaTeX code, but I only have some paint like software to show this here where I am). klk

  • Related (duplicate?): tex.stackexchange.com/questions/75834/… – Jake Aug 4 '16 at 19:15
  • @Jake, thank you for your comment. I did look at that, but I got stuck modifying it. It's made in some way that is a bit too advanced for this time of day. Will take another look at if after some sleep. – Eric Fail Aug 4 '16 at 21:48
  • 1
    It would be helpful if you composed a fully compilable MWE including \documentclass and the appropriate packages thatshows what you have tried and sets up the problem and shows exactly what you are stuck with. For instance, can you get as far as drawing the function and the vertical lines at a and b? Or is that also a problem? While solving problems can be fun, setting them up is not. Then, those trying to help can simply cut and paste your MWE and get started on solving the problem. – Peter Grill Aug 5 '16 at 7:37
  • @PeterGrill, will do ASAP. – Eric Fail Aug 5 '16 at 8:39
  • Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. – samcarter_is_at_topanswers.xyz Apr 4 '18 at 11:48

Well, @salim bou bit me for 6 minutes, but anyway (slightly different):

I reproduce your image with the following pure TikZ code:


% axes
\draw[->]  (-0.2,0) -- (8,0) node [below left] {$x$};
\draw[->]  (0,-0.2) -- (0,6) node [below left] {$y(x)$};
% grid
\draw[gray!30,thin]  (-1,-1) grid +(9,7);
% curve
\draw[red,very thick, name path=A]
    (1,2) .. controls +(1,0) and + (-1.5,-0.1) .. (4,3)
          .. controls +(1.5,0.1) and + (-1,0) .. (7,4);
% start, end of curve
\draw[dashed]  (1,-0.1) node[below] {$a$} -- (1,2);
\draw[dashed]  (7,-0.1) node[below] {$b$} -- (7,4);
% for determining intersections a and b
\path[name path=B]  (3,-0.1) node[below] {$x_0$} -- + (0,6);
\path[name path=C]  (5,-0.1) node[below] {$x_0 + \Delta x$} -- + (0,6);
% rectangles
\draw [name intersections={of=A and B, by=a},very thick,dashed, blue] 
    (5,0) -| (a) -| (5,0);
\draw [name intersections={of=A and C, by=b},very  thick,dotted,green] 
    (3,0) -| (b) -| (3,0);
% measure of \Delta x
\draw[<->]  (3,0.5) to ["$\Delta x$"] (5,0.5);
% comments:
\draw[<-]   (3.4,3.0) -- + (120:1) node[above] {$f(x_0+\Delta)\cdot\Delta x$};
\draw[<-]   (4.4,2.9) -- + (0:0.8) node[right] {$f(x_0+\Delta)\cdot\Delta x$};
\draw[<-]   (4.4,1.5) -- + (0:0.8) node[right] {$f(x_0)\cdot\Delta x$};

which gives:

enter image description here

Edit: with consideration with recent edit of question -- to MWE is added:

% comments:
\draw[<-]   (3.4,3.0) -- + (120:1) node[above] {$f(x_0+\Delta)\cdot\Delta x$};
\draw[<-]   (4.4,2.9) -- + (0:0.8) node[right] {$f(x_0+\Delta)\cdot\Delta x$};
\draw[<-]   (4.4,1.5) -- + (0:0.8) node[right] {$f(x_0)\cdot\Delta x$};

enter image description here






\draw [->](-0.5,0)--(8,0);
\draw [->](0,-0.5)--(0,6);
\draw [name path=graph](\a,1.5)coordinate(a)..controls (\xA,4) and (\b,2).. (\b,5)coordinate(b);
\path [name path=lineA](\xA,0)--+(0,6);
\path [name path=lineB](\xB,0)--+(0,6);
\draw [name intersections={of=lineA and graph},dashed,green]
(\xB,0)|-(intersection-1)--(intersection-1 |- 0,0)node [below,black]{\strut  $x_0$};
\draw [name intersections={of=lineB and graph},dashed,blue]
(\xA,0)|-(intersection-1)--(intersection-1 |- 0,0)node [below,black]{\strut $x_0+\Delta x$};
\draw [<->] ([yshift=3mm]\xA,0)--node[fill=white]{$\Delta x$}([yshift=3mm]\xB,0);
\draw [dashed,thin] (a)--(a|- 0,0)node [below]{\strut $a$};
\draw [dashed,thin] (b)--(b|- 0,0)node [below]{\strut $b$};



enter image description here

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.