# Proper way to change axis in plot tikz

I am trying to reconstruct the image below in tikz, and I think I have done a fairly decent job.

The problem is that my code is a mess. Is there any simple clean way to produce this image?

My main problem was the axis, and somewhat the scaling. Also the nodes are a huge mess ^^

\documentclass{article}
\usepackage{tikz}
\usepackage{tkz-euclide}
\begin{document}

\begin{tikzpicture}[x=0.02cm,y=0.02cm,scale=1]
\tkzInit[ymin=-40,ymax=390,xmin=-40,xmax=540]
\tkzClip
\draw[help lines,ultra thin,dashed,gray!50!white] (-50,-50) grid (550,400);
\coordinate [label=below right:{50}] (x_1) at (50,0);
\coordinate [label=below right:{}] (B) at (0,390);
\coordinate [label=above right:{\Large $y$}] (U) at (0,350);
\coordinate [label=above left:{\Large $x$}] (A) at (540,0);
\coordinate [label=below right:{50}] (x_1) at (50,0);
\coordinate [label=below right:{100}] (x_2) at (100,0);
\coordinate [label=below right:{150}] (x_3) at (150,0);
\coordinate [label=below right:{200}] (x_4) at (200,0);
\coordinate [label=below right:{250}] (x_5) at (250,0);
\coordinate [label=below right:{300}] (x_6) at (300,0);
\coordinate [label=below right:{350}] (x_7) at (350,0);
\coordinate [label=below right:{400}] (x_8) at (400,0);
\coordinate [label=below right:{450}] (x_9) at (450,0);
\coordinate [label=below right:{500}] (x_10) at (500,0);
\coordinate [label=below right:{0}] (O) at (0,0);
\coordinate [label=above left:{50}] (y_1) at (0,50);
\coordinate [label=above left:{100}] (y_2) at (0,100);
\coordinate [label=above left:{150}] (y_3) at (0,150);
\coordinate [label=above left:{200}] (y_4) at (0,200);\\
\coordinate [label=above left:{250}] (y_5) at (0,250);
\coordinate [label=above left:{300}] (y_6) at (0,300);
\coordinate [label=above left:{350}] (y_7) at (0,350);
\coordinate [label=above left:{\bf Kostnader per m\aa ned (kroner)}] (R) at (310,350);
\coordinate [label=above left:{\bf Ringetid (minutter)}] (K) at (540,20);
\tkzDefPoint(0,-50){C}
\tkzDefPoint(-50,0){D}
\tkzDefPoint(0,87.50){S}
\tkzDefPoint(500,337.50){T}
\tkzDrawSegment[thick,-stealth](D,A)
\tkzDrawSegment[thick,-stealth](C,B)
\tkzDrawSegment[ultra thick,red](S,T)
\end{tikzpicture}

\end{document}


My main question is, if there is a simpler way to create the axis. (nodes?)

-
You really should be using pgfplots for this. There are plenty of examples on the site. –  Alan Munn Nov 21 '11 at 14:32
Another vote for pgfplots. I did an example of one earlier today. The documentation for the package is extremely helpful and provides lots of examples to work with. –  qubyte Nov 21 '11 at 14:39
I am reading thrugh the documentation now, it seems as a very powerful tool. Alas I do not see anything about changing the default axis... I am perhaps blind. A –  N3buchadnezzar Nov 21 '11 at 14:52
Added an answer for you to have a play with. I really enjoy using pgfplots, so I think you're going to have fun with it. –  qubyte Nov 21 '11 at 14:58
Yes but pgfplots is the recommended tool but I have also fun to write codes with my packages. The code of the OP is not very optimized. tkz-euclide is used to create geometrical drawings. tkz-base is a tool for drawing with a cartesian coordinate system. You can define your axes with \tkzAxeX and tkzAxeYwith the options xstep and ystep(see my answer). –  Alain Matthes Nov 21 '11 at 16:40

Here's a rough version of the plot you want for you to play with.

\documentclass[10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}

\begin{document}

\begin{figure}[ht]
\begin{tikzpicture}
\begin{axis}[
scale only axis,
grid=major,
axis lines=middle,
inner axis line style={->},
xlabel={$x$ Ringetid (minutter)},
ylabel={$y$ Kostnader per måned (kroner)},
ytick={0,50,...,350},
xtick={0,50,...,500},
ymin=-10,
ymax=370,
xmin=-10,
xmax=520,
]
(0, 75)
(500, 340)
};
\end{axis}
\end{tikzpicture}
\end{figure}

\end{document}


which will give you this (thanks to Torbjørn for tricks to make this more succinct code):

It's not exactly the same, but you can get it there with a bit more tweaking.

-
A little easier way of defining the labels: xtick={0,50,...,500}, ytick={0,50,...,350}. You don't have to specify the labelticks as well. And you can add grid style={dashed} to get the dashed grid. –  Torbjørn T. Nov 21 '11 at 15:03
Noted. Those are a hangover from a plot which had lots of decimal places (very fine grain) which pgfplots approximated to 1. I stupidly updated them instead of taking them out, I'll take those out now. I left the grid style out on purpose though. Better to encourage exploration. –  qubyte Nov 21 '11 at 15:05
You can also plot a function with \addplot{0.54*x+70};. You just need to add domain=0:500,no markers to the axis options. –  percusse Nov 21 '11 at 15:32
@percusse: Using domain on its own doesn't work, because it spaces the ticks too far apart. I've updated the plot with what I think is the minimal to do this as the original figure specifies. As far as I can see, the easiest way to define a line is with two points, so in this case I see no reason to use a function. –  qubyte Nov 21 '11 at 17:14
Well actually, you could use axis lines=middle instead of separate statements for x and y. Similar for the arrow style of the axis, inner axis line style={->}. (Sorry for the nagging, forgot to mention these earlier.) –  Torbjørn T. Nov 21 '11 at 17:24

I agree with you, pgfplotsis the recommended tool to draw such graphics and tkz-euclideis a tool for some specific geometrical drawings but it's possible to draw a simple line with tkz-baseor with tkz-fct. tkz-basecan define coordinates to draw with euclide and(or) fct.

version A with tkz-fct this package loads tkz-base

\documentclass[]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{fullpage,amsmath,tkz-fct}

\begin{document}
\begin{tikzpicture}
\tkzInit[xmax=500,ymax=350,xstep=50,ystep=50] % to get the good coordinates
\tkzAxeX[label=$x$ Ringetid (minutter),above left=10pt]
\tkzAxeY[label=$y$ Kostnader per måned (kroner),below right=30pt]
\tkzGrid
\tkzFct[color = red, domain =0:500]{75+0.55*\x}
\end{tikzpicture}
\end{document}


version B with only tkz-base

\documentclass[]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{fullpage,amsmath,tkz-base}

\begin{document}
\begin{tikzpicture}
\tkzInit[xmax=500,ymax=350,xstep=50,ystep=50]
\tkzAxeX[label=$x$ Ringetid (minutter),above left=10pt]
\tkzAxeY[label=$y$ Kostnader per måned (kroner),below right=30pt]
\tkzGrid
\tkzDefPoint(0,75){A}
\tkzDefPoint(500,340){B}
\tkzDrawSegment[color=red](A,B)
\end{tikzpicture}
\end{document}


With the two versions, the result is :

-
@N3buchadnezzar I wrote tkz-fct for personal use while pgfplots was not yet written. Now the good way is to use pgfplots but with tkz or with pgfplots you need to look at the documentation. euclide and fct both use base to create drawings. –  Alain Matthes Nov 21 '11 at 16:31