# How to make these two graphs similar?

I want the left hand side of the following code's output to be exactly similar to the picture below. How can I do that?

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
\draw[->,color=black] (-1.5,0) -- (3.5,0);
\foreach \x in {-1,-1,1,2,3}
\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) node[below] {\footnotesize $\x$};
\draw[->,color=black] (0,-2.5) -- (0,3);
\foreach \y in {-2,-1,1,2,2.5}
\draw[shift={(0,\y)},color=black] (2pt,0pt) -- (-2pt,0pt);
\draw[color=black] (0pt,-1pt) node[below left] {\footnotesize $0$};
\clip(-1.5,-2.5) rectangle (3.5,3);
\draw [very thick,domain=-1.5:2.5] plot(\x,{-1*(\x)});
\draw [smooth, very thick,domain=-2:3] plot(\x,{-1*(\x)^2+2});
\node at (2,-2) [right] {\small $(2,-2)$};
\node at (.7,-1.2) [below ] {\small $y=-x$};
\node at (1,1) [right ] {\small $y=2-x^2$};
\node at (-1,1) [left ] {\small $(-1,1)$}; % this line, doesn't appear completely in the output.
\draw [fill=gray,fill opacity=0.3] plot [domain=-1:2](\x,{-1*(\x)^2+2}) -- plot [domain=-2:3] (\x,{-1*(\x)});
\end{tikzpicture}


-

## 1 Answer

The problem is that you are clipping it via \clip(-1.5,-2.5) rectangle (3.5,3);. So, I just moved the node to be before you do the clipping:

## Notes:

• I left the current bounding box draw command as a comment in the code as I find that useful in debugging these kind of things.
• As Marc van Dongen pointed out, the reason this solution works is that the \clip only affects what follows the clip, and you can see the clip path via the \clip[draw] option. Since you would not normally want the nodes clipped then you should probably place the nodes before you \clip.

## Code:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{arrows}

\begin{document}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
\draw[->,color=black] (-1.5,0) -- (3.5,0);
\foreach \x in {-1,-1,1,2,3}
\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) node[below] {\footnotesize $\x$};
\draw[->,color=black] (0,-2.5) -- (0,3);
\foreach \y in {-2,-1,1,2,2.5}
\draw[shift={(0,\y)},color=black] (2pt,0pt) -- (-2pt,0pt);
\draw[color=black] (0pt,-1pt) node[below left] {\footnotesize $0$};
\node at (-1,1) [left ] {\small $(-1,1)$}; % this line, didn't used to appear completely in the output.%
\clip(-1.5,-2.5) rectangle (3.5,3);
\draw [very thick,domain=-1.5:2.5] plot(\x,{-1*(\x)});
\draw [smooth, very thick,domain=-2:3] plot(\x,{-1*(\x)^2+2});
\node at (2,-2) [right] {\small $(2,-2)$};
\node at (.7,-1.2) [below ] {\small $y=-x$};
\node at (1,1) [right ] {\small $y=2-x^2$};

\draw [fill=gray,fill opacity=0.3] plot [domain=-1:2](\x,{-1*(\x)^2+2}) -- plot [domain=-2:3] (\x,{-1*(\x)});

%\draw [red, ultra thick] (current bounding box.south west) rectangle (current bounding box.north east);
\end{tikzpicture}
\end{document}

-
I was going to say the same but he probably also wants to clip the stuff to the right of the y-axis. I suggest explaining that the \clip command only affects what follows it. If you add the draw option to the \clip command (\clip[draw]), you can see the path that's used for clipping.... – Marc van Dongen Mar 5 '13 at 6:24
@MarcvanDongen +1 for the great tip! thanks. – Vahid Damanafshan Mar 5 '13 at 6:29
@MarcvanDongen: Thanks, I should have explicitly stated that. Have added it to the answer. – Peter Grill Mar 5 '13 at 6:35