TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 ^^


\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);
\tkzDrawSegment[ultra thick,red](S,T)


My attempt to create the plot

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

share|improve this question
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
up vote 9 down vote accepted

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




    scale only axis,
    axis lines=middle,
    inner axis line style={->},
    xlabel={$x$ Ringetid (minutter)},
    ylabel={$y$ Kostnader per måned (kroner)},
\addplot[color=red,thick] coordinates {
            (0, 75)
            (500, 340)


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

Simple pgfplot

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

share|improve this answer
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


\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]
\tkzFct[color = red, domain =0:500]{75+0.55*\x}

version B with only tkz-base


\tkzAxeX[label=$x$ Ringetid (minutter),above left=10pt]
\tkzAxeY[label=$y$ Kostnader per måned (kroner),below right=30pt]

With the two versions, the result is :

enter image description here

share|improve this answer
@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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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