I have drawn the following figure in Mathematica. It is plot of y <= 1/x

enter image description here

But when I inserted it in latex using \begin{figure}, it was inserted there but I could not control its position in my document. Sometimes it moves into the unwanted position.

So, I thought if I could draw the figure in Latex using tikz. Actually, I want to draw the following figure ...

enter image description here

Can I draw the same graph as above in Latex?

Please help me.


If you want to draw it in TikZ only, without using the axis environment (which I don't use, generally), here's a way to do that. It's what I use for my students.

fill under the inverse function


        \def\xmin{-9} \def\xmax{8}
        \def\ymin{-4} \def\ymax{6}
        \def\Mgrid{1} \def\mgrid{0.2}
        \draw[cyan!20,thin] (\xmin,\ymin) grid[step=\mgrid] (\xmax,\ymax);
        \draw[cyan] (\xmin,\ymin) grid[step=\Mgrid] (\xmax,\ymax);
        \draw[-Stealth] (\xmin,0) -- (\xmax,0);
        \draw[-Stealth] (0,\ymin) -- (0,\ymax);
        \foreach \x in {\xmin,...,-1,1,2,...,\xmax} \node[below] at (\x,0) {\footnotesize \strut \x};
        \foreach \y in {\ymin,...,-1,1,2,...,\ymax} \node[left] at (0,\y) {\footnotesize \strut \y};
        \clip (\xmin,\ymin) rectangle (\xmax,\ymax);
        \fill[red,opacity=0.3] (\xmin,\ymin) -- plot[domain=\xmin:-0.01,samples=100] ({\x}, {1/\x}) -- cycle;       
        \draw[thick,domain=\xmin:-0.01,red,samples=100] plot ({\x}, {1/\x});
        \fill[red,opacity=0.3] (0,\ymin) -- (0,\ymax) -- plot[domain=0.01:\xmax,samples=100] ({\x}, {1/\x}) -- (\xmax,\ymin) -- cycle;      
        \draw[thick,domain=0.01:\xmax,red,samples=100] plot ({\x}, {1/\x});

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.