Interpolating points between dates on a graph

edited March 2017 in Library Questions

So i'm trying to create a graph with the grafica library, and I have preset data with x/y axis already. The x axis is a timeline of dates at random intervals. What's the best to interpolate the points so that every day has an interpolated point so the graph appears smooth.

To see an example of how my graph currently looks, check out this example:

import grafica.*;

GPlot plot; 
GPointsArray myArray = new GPointsArray(0);
int nPoints = 100;

void setup() {
  size(500, 350);

  plot = new GPlot(this, 0, 0, 500, 350);
  myArray = new GPointsArray(nPoints);

  for (int i = 0; i < nPoints; i = i + (int)(random(1,15))) {
    myArray.add(i, 10*noise(0.1*i));
  }

  plot.setPoints(myArray);
  plot.defaultDraw();
}

It will come out something like this:

graph1

It should come out like this where instead of points every 1-15 ticks, it would be every tick.

graph2

Edit: And I read about lerp() and map() but i'm not sure how to actually apply it

Answers

  • edited March 2017

    @Joey --

    Your question relates to "curve fitting" and "smoothing" of data. Based on your explanation it seems you are more interested in curve fitting, and perhaps specifically approaches such as polynomial regression.

    There are many ways of doing fitting -- many different algorithms -- and producing output that is reasonable is highly dependent on what your data is. Also, it is generally bad form to hide your original, low-resolution data and fake high-resolution data. Instead, show the fit curve without points and in addition to (on top of) the point data that you used to generate it. The low resolution data may not look as good, but it is usually more honest and less speculative.

    Where is your data coming from? If Grafica doesn't support polynomial fit curves and you don't want to implement them yourself (they are parametrized and fiddly) then you may want to generate your smoothed data wherever you are working with your real data, before the sketch -- R, Python, whatever,

Sign In or Register to comment.