10

I want to redraw the following graphic in pgf/TikZ.

graphic to redraw

I struggle to draw the rotated paraboloid/the root function. I come this far:

\documentclass{minimal}
\usepackage{tikz}
\begin{document}
\begin{center}
\begin{tikzpicture}[scale=1,cap=round]
    \tikzstyle{axes}=[]
    \tikzstyle{important line}=[very thick]
    \colorlet{setcolor}{green!50!black}

    % help lines
    \draw[style=help lines,step=1cm] (-4.4,-4.4) grid (4.4,4.4);

    \draw (4.4,2) parabola bend(-1,0) (4.4,-2);

    \begin{scope}[style=axes]
        \draw[->] (-4.5,0) -- (4.5,0) node[right] {$x$};
        \draw[->] (0,-4.5) -- (0,4.5);
        \draw[xshift=1 cm] (0pt,1pt) -- (0pt,-1pt) node[below,fill=white] {$1$};
        \draw[yshift=1 cm] (1pt,0pt) -- (-1pt,0pt) node[left,fill=white] {$1$};
    \end{scope}

\end{tikzpicture}
\end{center}
\end{document}

solution so far

I searched the documentation of pgf/TikZ, but am unable to find a solution.


Incorporating the solution of percusse, it is unfortunately being rendered as follows for me:

enter image description here

I am still looking into this. Maybe I need a newer version of pgf/TikZ or pgfplots.


Building on the solution of percusse, I just used a different filling method and got it working.

\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{patterns}

\begin{document}
\begin{center}
  \begin{tikzpicture}
    \begin{axis}[no markers,domain=-1:2,samples=500,xmin=-2,xmax=2,y post scale=0.8,grid=major]
      \addplot[black] {sqrt(x+1)};
      \addplot[black,fill=green!20!white,opacity=.6] {-sqrt(x+1)} |- (axis cs:-1,3);
    \end{axis}
  \end{tikzpicture}
\end{center}
\end{document}

My final solution

Thank you!

  • It seems from the documentation that tikx only draws parabolas like $y=x^2$, not $x = y^2$. You can rotate it in place though with \draw[rotate=-90] (-2,4.4) parabola bend(0,-1) (2,4.4); – mrf Jun 27 '12 at 20:43
  • @mrothe: Is that the result you get from just compiling percusse's document, without any changes? – Jake Jun 28 '12 at 08:00
  • Mine renders fine – N3buchadnezzar Jun 28 '12 at 08:10
  • If you want to see the current version of your files, do what Gonzalo said here. Add \listfiles in your preamble, and search the log file for the version. For comparison, my version of pgfplots is pgfplots.sty v1.5.1. – Alenanno Jun 28 '12 at 09:06
  • @Jake, yes, sorry, that's from just compiling percusse's document. –  Jun 28 '12 at 11:49
  • @Alenanno: I have pgfplots v1.5. I am currently in the process of upgrading pgfplots. –  Jun 28 '12 at 11:51
  • If everything is updated to TikZ/PGF 2.10 and pgfplots 1.5.1, try also the suggestion given in this nice answer to modify the hatching which looks a little too crowded : Custom fill patterns – percusse Jun 28 '12 at 12:06
  • Updating pgfplots to 1.5.1 does not solve the problem. –  Jun 28 '12 at 14:33

2 Answers2

12

For such purposes pgfplots is the ideal tool.

\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{patterns}

\begin{document}
\begin{tikzpicture}
\begin{axis}[no markers,domain=-1:2,samples=100,xmin=-2,xmax=2,y post scale=0.8,grid=major]
\addplot[black] {sqrt(x+1)};
\addplot[black,pattern color=red,pattern=north east lines] {-sqrt(x+1)} |- (axis cs:-1,3);
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

percusse
  • 157,807
1

A possibility

\documentclass[11pt]{scrartcl}
\usepackage{tikz}
\usetikzlibrary{patterns}
\begin{document}
\begin{tikzpicture}[x={(0,1cm)},y={(1 cm,0)}] 
  \path [domain=-2:0,pattern color=red,
         pattern=north east lines,
         fill opacity=.5] (0,-1) -- (2,-1)--(2,3) -- plot  (\x,\x*\x-1) --cycle ;  
  \draw [red,domain=-2.5:2.5,samples=100, thick]  plot (\x,\x*\x-1) ;  
    \draw[thin,blue] (-2,0) -- (2,0) ;
  \draw[thin,blue] (0,-2) -- (0,4);  
  \draw[->,thick] (0,0) -- (1,0) ;
  \draw[->,thick] (0,0) -- (0,1);        
\end{tikzpicture}
\end{document} 

enter image description here

Alain Matthes
  • 95,075