# Graphing a line from two coordinates

Very new LaTeX user here!

There are a ton of impressive graphs on this site. I, however, am trying to make a nice looking line on a simple graph by plotting two (x,y) coordinates: (8, 2) and (-2, -3).

I've found a lot of information on parabolic graphs and much more advanced stuff, but nothing on really simple graphs.

\begin{tikzpicture}
\draw [thin, gray, ->] (0,-5) -- (0,5)
node [above, black] {$y$};
\draw [thin, gray, ->] (-10,0) -- (10,0)
node [right, black] {$x$};
\draw [draw=red,ultra thick] (8,2) -- (-2,-3);
\end{tikzpicture}


I spent a long time trying to figure this out and mad a pretty stupid looking graph (which is huge):

I would recommend using pgfplots instead of directly using tikz:

## Notes

• The reason for suggesting the use of pgfplots (instead of tikz) is that tikz is designed for drawing and pgfplots (which uses tikz) is designed specifically for graphing. So, if what you are doing is graphing, you should use the tool that was designed for that. Sure, you can use tikz (especially for the image given in the question), but then when you want to add tick marks, a grid, perhaps a legend in the case of multiple equations on one graph, you end up doing a lot of the work that pgfplots has already done for you.

## Code:

\documentclass{article}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot [mark=none,  red,   ultra thick] coordinates { (8,2) (-2,-3)};
\end{axis}
\end{tikzpicture}
\end{document}

• Why do you recommend so? – Jan Dec 25 '16 at 8:22
• @PeterGrill: I am sure, I am not the only one, being curious about your recommendation. Hence my question/comment. Maybe you should add this valuable information into your answer? Merry christmay to you. – Jan Dec 25 '16 at 12:44
• @Jan: Answer updated to include the answer to your question. – Peter Grill Dec 25 '16 at 14:17

For comparison of drawing with pure tikz and pgfplots:

\documentclass{article}
\usepackage{pgfplots}

\begin{document}
\begin{center}
with pure TikZ:

\begin{tikzpicture}[scale=0.6]
% grid
\draw [densely dashed, gray!50]    (-6,-6) grid (6,6);
% ticks
\foreach \i in {-5,...,-1,1,2,...,5}
{
\draw (\i,0.1) -- ++ (0,-0.2) node[below,font=\scriptsize] {$\i$};
\draw (0.1,\i) -- ++ (-0.2,0) node[left, font=\scriptsize] {$\i$};
}
% axis
\draw [->] ( 0,-6) -- (0,6) node [left ] {$y$};
\draw [->] (-6, 0) -- (6,0) node [below] {$x$};
% graph
\draw [draw=red,thick] (-2,-6) -- (2,6);
\fill[red] (-1,-3) circle (1.5mm) (1,3) circle (1.5mm);
\draw [draw=blue]   (-6,-5) -- (6,1);
\end{tikzpicture}

with pgfplots:

\begin{tikzpicture}[>=latex]
\begin{axis}[
%width=6cm,
axis lines=middle,
grid,
grid style={densely dashed},
xlabel=$$x$$, ylabel=$$y$$,
every axis plot/.style={very thick},
]