# How to draw a coordinate system with LaTeX?

I want to draw a coordinate system like this:

I would like to specify the width and height of the coordinate system and where the origin begins (upper left corner). I also want to specify the x and y axes with arrows. Additionally the end of the x and y axis should be indicated with the text "200px".

I'm a LaTeX beginner and am not sure how to do that.

Can anyone recommend a latex package for it?

-
The first choices would be TikZ or PsTricks, associated with TikZ you also have pgfplots –  Peter Jansson Feb 17 '13 at 14:09
You should look into the package pgf (also named tikz in its front-end layer) or pstricks. Both have amazing drawing capabilities and support just what you request. –  zeroth Feb 17 '13 at 14:09
Thank you very much. The TikZ package is great! –  Benny Neugebauer Feb 17 '13 at 14:51

The TikZ package is great! I did the following:

\documentclass{article}
\usepackage{tikz}
\begin{document}

% TikZ picture with origin upper left
\begin{tikzpicture}[yscale=-1]
% 4x4 grid
\draw (0, 0) grid (4, 4);
% origin point
\draw [color=blue, fill=blue] (0, 0) circle (0.1);
% x-axis
\draw [thick,->] (0, 0) -- (4.5, 0);
% y-axis
\draw [thick,->] (0, 0) -- (0, 4.5);
% origin label
\node at (-0.1, -0.5) {(0, 0)};
% x-axis label
\node at (4.5, -0.5) {200px};
% y-axis label
\node at (0, 5) {200px};
\end{tikzpicture}

\end{document}


Output:

Very helpful: A brief introduction into TikZ

-
This seems to make the boxes checkboxes. If I click one of them in Preview, a checkmark appears. –  asmeurer Dec 9 '13 at 19:54

Tikz or pstricks are more powerful but LaTeX has a built in coordinate drawing system, and you really don't need to load an external package for this (although I loaded color)

\documentclass{article}
\usepackage{color}
\begin{document}

\setlength\unitlength{10pt}

\begin{picture}(20,10)(0,-10)
\thicklines
\put(0,0){\line(1,0){20}}
\put(0,0){\line(0,-1){10}}
\put(0,-10){\line(1,0){20}}
\put(20,0){\line(0,-1){10}}
\put(0,0){\circle*{.3}}
\put(0,0){\vector(1,0){4}}
\put(0,0){\vector(0,-1){4}}
\thinlines
\put(0,0){\makebox(0,0)[tl]{\tiny(0,0)}}
\put(4,0){\makebox(0,0)[cb]{\tiny x}}
\put(0,-4){\makebox(0,0)[cr]{\tiny y}}
\color[rgb]{.8,.8,.8}
\multiput(1,0)(1,0){19}{\line(0,-1){10}}
\multiput(0,-1)(0,-1){9}{\line(1,0){20}}

\end{picture}%

\end{document}

-
It's good that this has a non-TikZ answer, but I feel like this is a good example of why bloated packages like TikZ or PSTricks are useful even for rather simple tasks. Man, code for graphics with plain LaTeX is scary! –  Jake Feb 17 '13 at 15:30
Thank you for this! It's good to know that the standard can do this. But I prefer the TikZ-way. :) –  Benny Neugebauer Feb 17 '13 at 19:01

With PSTricks.

\documentclass[pstricks,border=18pt]{standalone}
\usepackage{pst-plot}
\begin{document}
\begin{pspicture}[showgrid](5,-5)
\psaxes[labels=none,ticks=none]{->}(0,0)(5,-5)[200px,90][200px,-90]
\pscircle*(0,0){2pt}
\uput[90](0,0){$(0,0)$}
\end{pspicture}
\end{document}


It is also possible to create non-orthogonal coordinate system with PSTricks as follows. Here, OI and OJ are the unit vectors that are parallel to x and y axes, respectively.

\documentclass[pstricks,border=18pt]{standalone}
\usepackage{pst-eucl}

\begin{document}
\begin{pspicture}[showgrid](5,-5)
\pstGeonode[PosAngle={135,45,180}]
(0,0){O}
(1;-15){I}
(1;-75){J}
\pstOIJGeonode[PointName=none,PointSymbol=none](5,0){I'}{O}{I}{J}(0,5){J'}
\pstOIJGeonode[PosAngle={-45,45},PointName={{R(4,2)},{A(4,0)},{B(0,2)}},PointNameSep=2em](4,2){R}{O}{I}{J}(4,0){A}(0,2){B}
\psline[linecolor=cyan]{->}(O)(I')
\psline[linecolor=cyan]{->}(O)(J')
\uput[-15](I'){$x$}
\uput[-75](J'){$y$}
\psline[linecolor=orange](A)(R)(B)
\end{pspicture}
\end{document}


It might be unavailable in TikZ or others.

## Warning

The syntax of \pstOIJGeonode is a bit uncommon as follows.

\pstOIJGeonode(x1,x2){A1}{O}{I}{J}(x2,y2){A2}...(xn,yn){An}


The first point A1 must come right after \pstOIJGeonode but the remaining points A2, ..., An must come right after {O}{I}{J}`. I don't know why the author made such a strange syntax.

-