# [Tex/LaTex] Drawing simple graphs on LaTeX

graphics

Let me just say I am NOT drawing graphs from Graph Theory. I am just strictly asking about simple graphs we do in algebra.

I just started with MiKTeX and I am trying to read and absorb everything in the "The Not So Short Introduction to LaTeX" on drawing pictures and graphics.

However I've noticed that to draw even the simplest graph like a rectangle on the first quadrant, you have to be VERY specific with the \put(x, y){\line(x1, y1){length}} command.

Is there a faster way? Yes I realize usually people import graphs from software devices like Maple or Mathematica but I don't have those right now.

Could someone teach me a quick way of drawing them? An example I want to draw is:

a triangle formed by x + y = 1 and the coordinate axis on xy-plane.

My best attempt at this is

\setlength{\unitlength}{2mm}
\begin{picture}(10,20)
\put(0,0){\vector(1,0){40}}
\put(0,0){\vector(0,1){40}}
\put(10,0){\line(-5,6){10}}
\put(10,0){\line(5,-6){10}}
\end{picture}


Unfortunately it displays nothing like I intended.

\put(10,0){\line(-5,6){10}}
\put(10,0){\line(5,-6){10}} does opposite things as I wanted a line straight through.


Could someone also detailedly explain to me what do the parameters (x,y) do after \begin{picture}(x,y)?

I would recommend you use pgfplots for these kind of graphs:

If some of these options are not clear, the best way is to comment them out and see the effect on the graph.

## Code:

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin=-1, xmax=2,
ymin=-1, ymax=2,
axis lines=center,
axis on top=true,
domain=0:1,
]

\end{axis}
\end{tikzpicture}
\end{document}


Alternatively you could do this just in tikz:

## Code:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw [thin, gray, ->] (0,-1) -- (0,2)      % draw y-axis line
node [above, black] {$y$};              % add label for y-axis

\draw [thin, gray, ->] (-1,0) -- (2,0)      % draw x-axis line
node [right, black] {$x$};              % add label for x-axis

\draw [draw=red,ultra thick] (0,1) -- (1,0);% draw the graph

\node [left] at (0,1) {$1$};                % label y-intercept
\node [below] at (1,0) {$1$};               % label x-intercept
\end{tikzpicture}
\end{document}