# Thread: How to draw a graph

1. ## How to draw a graph

I'm trying to create a calculus exam using LaTeX, and I want to draw a graph with discontinuities, asymptotes, etc.

I'm trying to model the first part of the graph on [-9, -6) as -1/(x+6)

When I type the following it works fine on [-9, -7]

\begin{center}
\mbox{\beginpicture
\setcoordinatesystem units <.7cm, 1cm>
\setplotarea x from -9 to 5, y from -5 to 5
%% x axis:
\arrow <.1in> [.15, .5] from -9 0 to 5 0
\axis top shiftedto y=0 ticks out at -9 -8 -7 -6 -5 -4 -3 -2 -1 1 2 3 4 / /
\axis bottom shiftedto y=0 ticks out numbered at -8 -4 4 / /
\axis bottom shiftedto y=0 ticks out at -7 -6 -5 -3 -2 -1 1 2 3 / /
%% y axis:
\arrow <.1in> [.15, .5] from 0 -5 to 0 5
\axis left shiftedto y=0 ticks in at -5 -4 -3 -2 -1 1 2 3 4 5 / /
\axis left shiftedto y=0 ticks out numbered at -4 -2 2 4 / /
\axis left shiftedto y=0 ticks out at -5 -3 -1 1 3 5 / /
\setplotsymbol ({\large .})
%%
%% Graph of y = -1/(x+6)
%%
\plot
-9 0.3333333
-8.75 0.36364
-8.5 0.4
-8.25 0.44444
-8 0.5
-7.75 0.57143
-7.5 0.666666
-7.25 0.8
-7 1
/
\endpicture}
\end{center}

However if I try to add the point (-6.75, 1.3333) to my list LaTeX returns an error and won't compile. Does anyone know why that is, or, better yet, a better way to do what I'm trying to do?

2. Originally Posted by Diamondlance
I'm trying to create a calculus exam using LaTeX, and I want to draw a graph with discontinuities, asymptotes, etc.

I'm trying to model the first part of the graph on [-9, -6) as -1/(x+6)

When I type the following it works fine on [-9, -7]

\begin{center}
\mbox{\beginpicture
\setcoordinatesystem units <.7cm, 1cm>
\setplotarea x from -9 to 5, y from -5 to 5
%% x axis:
\arrow <.1in> [.15, .5] from -9 0 to 5 0
\axis top shiftedto y=0 ticks out at -9 -8 -7 -6 -5 -4 -3 -2 -1 1 2 3 4 / /
\axis bottom shiftedto y=0 ticks out numbered at -8 -4 4 / /
\axis bottom shiftedto y=0 ticks out at -7 -6 -5 -3 -2 -1 1 2 3 / /
%% y axis:
\arrow <.1in> [.15, .5] from 0 -5 to 0 5
\axis left shiftedto y=0 ticks in at -5 -4 -3 -2 -1 1 2 3 4 5 / /
\axis left shiftedto y=0 ticks out numbered at -4 -2 2 4 / /
\axis left shiftedto y=0 ticks out at -5 -3 -1 1 3 5 / /
\setplotsymbol ({\large .})
%%
%% Graph of y = -1/(x+6)
%%
\plot
-9 0.3333333
-8.75 0.36364
-8.5 0.4
-8.25 0.44444
-8 0.5
-7.75 0.57143
-7.5 0.666666
-7.25 0.8
-7 1
/
\endpicture}
\end{center}

However if I try to add the point (-6.75, 1.3333) to my list LaTeX returns an error and won't compile. Does anyone know why that is, or, better yet, a better way to do what I'm trying to do?
A better way is to generate the figure with a specialist tool outside of LaTeX (Matlab, Mathematica, ... ) save the graph as a graphics file and include that in your document.

CB

3. I figured as much...but I'm still curious as to why adding a point causes problems.

4. In general, I'd agree with CB. However, I do have to say that LaTeX I've found to be very persnickety when it comes to graphs. Everything has to be just right. The graphic has to be in eps format (which is not terribly difficult; Mathematica does output graphs and other pictures in that format), and the syntax for inclusion has to be just right, and the file has to be in the right place. There's a fair amount to it.

5. Originally Posted by Ackbeet
In general, I'd agree with CB. However, I do have to say that LaTeX I've found to be very persnickety when it comes to graphs. Everything has to be just right. The graphic has to be in eps format (which is not terribly difficult; Mathematica does output graphs and other pictures in that format), and the syntax for inclusion has to be just right, and the file has to be in the right place. There's a fair amount to it.
PDFLaTeX and other compilers allow formats other than eps most of the illurstarations in the MHFzine are png's

CB

6. I think GNUPlot has a direct latex output (as well as eps and a ton of others).