Whats the best way of interpolating a graph and show the interpolation like this (using pgfplots): Interpolation
(source: blueleafsoftware.com)

I have the following code for my plot in an axis environment:


Should I plot the individual lines as individual addplot?


  • Is it a particlar point or just eyeballing?
    – percusse
    Commented Sep 12, 2014 at 11:54
  • Well, I'd prefer a particular point, but eyeballing would work too! Commented Sep 12, 2014 at 12:59

2 Answers 2


A PSTricks solution:



  \psline[linestyle = #1](0,#3)(#2,#3)(#2,0)


\psset{xunit = 2, yunit = 1.5}
    labels = none,
    xticksize = -0.14 5,
    yticksize = -0.105 4,
    tickwidth = 0.5pt,
    tickcolor = gray!50
    dotsize = 3pt 2,
    dotstyle = Bo
    linewidth = 1.2pt,
    linecolor = blue,
    showpoints = true,
    fillcolor = red



Notice that all you have to do is choose the coordinates for the points, i.e., the values of \xA,...,\xE and \yA,...,\yE, and the drawing will adjust accordingly.


Notice that had it not been for the labels on the axes, we could have defined the points using \pnodes instead of all the \defs. (There may be a smart way of defining the coordinates for the points but I don't know of it.)

  • Do you think I'd somehow be able to implement this with my current axis environment with pgfplots? Commented Sep 12, 2014 at 12:58
  • @SheheryarZaidi I don't know PGFPlots so I cannot help you with that---sorry! Commented Sep 12, 2014 at 13:03

It is quite easy to achieve what you want. Please have a look at the comments in the code.

% used PGFPlots v1.16
        % only show ticks at the data point ...
        xtick=data,                 ytick=data,
        % ... with numbered labels
        % change `clip mode` thus nodes of TikZ stuff outside the axis area
        % is not clipped away (i.e. the $x$ and $y$ label)
        clip mode=individual,
        % plotting points with connecting lines is PGFPlots default,
        % thus the easiest way is to provide the data as a table
        % (either inline as here or as data file)
        \addplot table {
            x   y
            0.5 1
            1.5 1.5
            3   4
            4   5
            % now you can specify a point where you want to add a "interpolated point"
            coordinate [pos=0.5] (A)

        % draw the horizontal and vertical lines to the axis start points
        \draw [dashed] ({rel axis cs:0,0} |- A)
            % including the labels
            node [left] {$y$}
                -| ({rel axis cs:0,0} -| A)
            node [below] {$x$};
        % draw a circle at the "interpolated point" with the same marker size as before
        % (2pt is the default/initial value)
        \filldraw [red] (A) circle (2pt);

image showing the result of above code

  • Would there be a way to instead of specifying the percentage where the point A would be placed, to instead type te exact x of A then have it interpolate into the y value?
    – Felipe9
    Commented Jul 19 at 16:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .