Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I need to make a picture that should look like

image

I saw a similar question here but the red function line appears neither when I use --shell-escape nor when I use --enable-write18. I use TeXstudio, by the way. TikZ and pgf packages are installed.

UPD: Code which I used

    \documentclass[]{scrartcl}
\usepackage{tkz-fct}   

\begin{document}
\begin{tikzpicture}[scale=1.25]
\tkzInit[xmax=8,ymax=4]
\tkzAxeXY[ticks=false]
\tkzGrid   
\tkzFct[color = red, domain =0.125:8]{4./x}
\tkzDrawRiemannSumInf[fill=green!60,
                     opacity=.2,
                     color=green,
                     line width=1pt,
                     interval=1:8,
                     number=7] 
 \foreach \x/\t in {1.5/$a_1$,2.5/$a_2$,3.5/$a_3$,7.5/$a_7$}
 \node[green!50!black] at (\x,{4/(\x+1)-0.25}){\t};  
\end{tikzpicture}   
\end{document} 

And maybe there are some good graphic editors to draw such things by hand?

share|improve this question
    
Can you post your code too? Which answer are you using? –  percusse Apr 24 '13 at 12:30
    
FYI, you don't need --shell-escape to use tikz & friends. –  Jubobs Apr 24 '13 at 12:31
2  
@Jubobs: I think Danil is using the tkz solution that uses gnuplot, and therefore needs shell-escape –  Jake Apr 24 '13 at 12:33
    
@percusse oh i used marked answer by Alain Matthes –  Danil Gholtsman Apr 24 '13 at 12:37
    
@Jubobs yes, Jake is right. –  Danil Gholtsman Apr 24 '13 at 12:38
show 1 more comment

1 Answer

up vote 3 down vote accepted

You could use the pgfplots answer, which does not rely on external programs to calculate the function:

\documentclass{article}

\usepackage{pgfplots}

% right hand sums
\pgfplotsset{
    right segments/.code={\pgfmathsetmacro\rightsegments{#1}},
    right segments=3,
    right/.style args={#1:#2}{
        ybar interval,
        domain=#1+((#2-#1)/\rightsegments):#2+((#2-#1)/\rightsegments),
        samples=\rightsegments+1,
        x filter/.code=\pgfmathparse{\pgfmathresult-((#2-#1)/\rightsegments)}
    }
}


\begin{document}
\begin{tikzpicture}[/pgf/declare function={f=4/x;}]
\begin{axis}[
    xmin=0,xmax=8.5,ymin=0,ymax=4,
    domain=0:8.5,
    samples=100,
    axis lines=left,
    clip=false,
    restrict y to domain=0:4
]
\addplot [thick, red] {f};
\addplot [
    black!80,fill=green,opacity=.3,
    right segments=7,
    right=1:8,
] {f};

\draw [ultra thick, black!60, -latex] (axis cs:1.5,0) -- ++(0,-5ex) node [anchor=north, black] {thread 1};
\draw [ultra thick, black!60, -latex] (axis cs:2.5,0) -- ++(0,-8ex) node [anchor=north, black] {thread 2};
\draw [ultra thick, black!60, -latex] (axis cs:7.5,0) -- ++(0,-5ex) node [anchor=north, black] {thread n};
\end{axis}
\end{tikzpicture}



\end{document}
share|improve this answer
    
oh, thanks it helped! –  Danil Gholtsman Apr 24 '13 at 12:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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