How can I create a simple coordinate system with a linear line in LaTeX using the tikz package? It should look something like this. With the iterating numbers on each axis and all.

enter image description here

  • 6
    Did you read the first tutorial in pgfmanual? – Ignasi Jan 21 '14 at 11:44

Use the tkz-euclide package for simple output.


   \draw[ thick,latex-latex] (-1,4) -- (4,-6) node[anchor=south west] {$a$}; % two points for drawing 2x+y=2
  \tkzText[above](0,6.75){Desired Output}



  • Works great, do you know if it is possible to add title/header above the coordinate system? – Oskar Persson Jan 21 '14 at 13:19
  • 1
    @OskarPersson, use \tkzText [above](0,6.5){$E=mc^2$} for insert text whenever you want. – ferahfeza Jan 21 '14 at 14:42

What, no pgfplots example?

enter image description here

  axis lines=middle,
  axis line style={Stealth-Stealth,very thick},
  xtick distance=1,
  ytick distance=1,
  title={Wonderful plot},
  grid style={thin,densely dotted,black!20}]
\addplot [Latex-Latex,domain=-5:3,samples=2] {x*2/3} node[right]{$a$};

This is one possible solution. Here both Euclidean and polar coordinates are presented. Furthermore, Give two points, a line is drawn by extending the end points

extended line/.style={shorten >=-#1,shorten <=-#1}

A macro drawing a line, given two points, is added.

\draw [extended line=1cm,stealth-stealth] (#1,#2)--(#3,#4);

enter image description here


\draw [extended line=1cm,stealth-stealth] (#1,#2)--(#3,#4);
\begin{tikzpicture}[scale=1.5,extended line/.style={shorten >=-#1,shorten <=-#1},]
\draw [help lines] (-3,-3) grid (3,3);
% Euclidean
\draw [->](0,-2.2)--(0,2.2) node[right]{$y$};
\draw [->](-2.2,0)--(2.2,0) node[right]{$x$};
% polar coordinate
\draw (0,0)--(2,2)node[anchor=south west]{$x+jy=r\angle \theta$};
\draw [thin,dashed] (2,2)--(2,0);
\draw (0.8,1)node[anchor=west,rotate=45]{$r=\sqrt{x^2+y^2}$};
\draw [fill=green](0,0) -- (0.75,0) arc (0:45:0.75cm);
\draw (1,0.3) node[rotate=10]{$\theta=\tan^{-1} \frac{y}{x}$};
\fill [red](2,2) circle(2pt);

% draw ticks and its labels
\foreach \x/\xtext in {-2/-2, -1.5/-\frac{3}{2}, -1/-1, -0.5/-\frac{1}{2}, 0.5/\frac{1}{2}, 1/1, 1.5/\frac{3}{2}, 2/2}
{\draw (\x cm,1pt ) -- (\x cm,-1pt ) node[anchor=north] {$\xtext$};}
\foreach \y/\ytext in {-2/-2, -1.5/-\frac{3}{2}, -1/-1, -0.5/-\frac{1}{2},0.5/\frac{1}{2}, 1/1, 1.5/\frac{3}{2}, 2/2}
{\draw (1pt,\y cm) -- (-1pt ,\y cm) node[anchor=east] {$\ytext$};}

% draw lines
\draw [extended line=1cm,stealth-stealth] (-2,-1)--(1,2) node[above]{a};  % method 1
\drawaline{0}{-2}{-2}{0}                                                  % method 2

  • Do you have simple example where it can just render the line for 2x +y = 2 – Oskar Persson Jan 21 '14 at 12:05
  • Yes, just draw two points and extend it. I will update my post – Jesse Jan 21 '14 at 12:20

A PSTricks solution:




 \psset{unit = 0.7}
 \caption{Plot of a line.}

\noindent This is Figure~\ref{figure:1}.




Just another fun with PSTricks.



    \rput(*5.2 {\f}){$a$}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.