CSharp
CSharp

Reputation: 1476

Rescale axis data to fixed size

I have a number of x/y data points of varying sizes and I need to rescale each one to the same fixed size.

For example, given two sets of x/y data where the first has 12 data points and the second 6. The maximum y value of the first is 80 and the second 55:

X1 = np.array([ 1, 2, 3, 4, 5, 6 ,7, 8, 9, 10, 11, 12 ])
Y1 = np.array([ 10, 20, 50, 55, 70, 77 ,78, 80, 55, 50, 21, 12 ])

X2 = [ 1, 2, 3, 4, 5, 6 ]
Y2 = [ 10, 20, 50, 55, 50, 10 ]

How can I rescale this data so that they both have 8 data points and the maximum y value is 60? I'm developing in python with numpy/matplotlib.

Upvotes: 0

Views: 40

Answers (1)

GorillazOnPlane
GorillazOnPlane

Reputation: 401

If you want to add/remove points from a data set my first idea would be to do a regression on the data set with np.polyfit or scipy.optimize.curve_fit (depending on what kind of function you expect your points to follow), then generate new points from that regression.

new_x_points = [1, 2, 3, 4, 5, 6, 7, 8]
coeff = np.polyfit(X1, Y1, deg = 2)
new_y_points = np.polyval(coeff, new_x_points)

Moving points from an interval (a,b) to the interval (c,d) is purely a mathematical problem. If x is on the interval (a,b) then

f(x) = (x - a) * h + c
where 
h = (d - c)/(b - a)

is a linear map to the interval (c, d).

Upvotes: 1

Related Questions