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).

Can somebody please help me with this? Here's what I had in mind: http://www.algebrahelp.com/worksheets/cache/graph_10027_a.png

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

Here's what I made:

    \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);  

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

My stupid graph


2 Answers 2


I would recommend using pgfplots instead of directly using tikz:

enter image description here


  • 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.



    \addplot [mark=none,  red,   ultra thick] coordinates { (8,2) (-2,-3)};
  • Why do you recommend so?
    – Jan
    Dec 25, 2016 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, 2016 at 12:44
  • 1
    @Jan: Answer updated to include the answer to your question. Dec 25, 2016 at 14:17

For comparison of drawing with pure tikz and pgfplots:


with pure TikZ:

% 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);

with pgfplots:

axis lines=middle,
grid style={densely dashed},
xlabel=\(x\), ylabel=\(y\),
every axis plot/.style={very thick},
    \addplot coordinates { (8,2) (-2,-3)};

enter image description here


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .