6

How to create simple graph in latex. x,y axis with straight line drawn at (0,0) at 45 degress through the x,y axis.

The graphs here are excellent but just too complicated for newcommers.


here is the link

enter image description here

Werner
  • 603,163
tmk
  • 69

2 Answers2

9

You can use TikZ (the manual is really great and it has numerous examples; there's also a Minimal introduction to TikZ):

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[scale=3]
\draw[->] (-1,0) -- (1,0) node[right] {$x$}; 
\draw[->] (0,-1) -- (0,1) node[above] {$y$};
\draw[blue] +(225:1.4) -- +(45:1.4);
\end{tikzpicture}

\end{document}

enter image description here

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\draw[->] (0,0) -- (5,0); 
\draw[->] (0,0) -- (0,5);
\draw[blue] (0,0) -- +(45:7);
\foreach \i/\text in {1.4/year,2.8/age,4.2/type,5.6/speed}
  \draw[fill=white,draw=blue] (45:\i) circle (2pt) node[left,xshift=-2pt] at (45:\i) {\text};
\node[anchor=west] at (0,-10pt) {Colour};
\node[anchor=east] at (5,-10pt) {Make};
\node[anchor=east,text width=1cm,align=left] at (-10pt,10pt) {Engine};
\node[anchor=east,text width=1cm,align=left] at (-10pt,4.8) {Car};
\end{tikzpicture}

\end{document}

enter image description here

Gonzalo Medina
  • 505,128
  • Thank you Gonzalo, well appreciated. will try to customize this sample, spent all day on this. the graph is actually a right angle one with straight line drawn from (0,0) to any number range. trying to label x,y and specifying my position e.g. top left, bottom left would not work. Also, tried getting dotted circle on the straight line through (0,0) to contain text but, that also was a nightmare. – tmk Aug 16 '12 at 21:09
  • sorry everyone, the boxes around the text in the graph are not needed. this was drawn using ms word. – tmk Aug 16 '12 at 21:59
  • @tmk I've updated my answer with a possible simple way to draw your diagram. – Gonzalo Medina Aug 16 '12 at 22:14
  • Thank you Gonzalo, your contribution is well appreciated. I have just been looking at the "pgfplots" you recommended, it is great and will get myself up to scratch in this. thank you. – tmk Aug 16 '12 at 22:22
8

For plotting functions or data, pgfplots which is based on TikZ, is useful. A simple example is given below, and the manual has many more.

\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[axis lines=center]
  \addplot [mark=none] {x};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

Torbjørn T.
  • 206,688