# Interpolating functions on your data using Python [PART 2]

Hey scientist! How is it going?
Today we’ll talk more about interpolation. We’ll use radial basis functions, tougher tools for a more civilized age. Let’s do this!

In order to use radial basis functions on SciPy we’ll use Rbf, a function within interpolate.rbf. Just like interp1d, Rbf generates a function. It receives an argument, ‘function’, which specifies the function used on the interpolation. The default function is ‘multiquadric’.

The valid arguments are ‘multiquadric’, ‘inverse’, ‘gaussian’, ‘linear’, ‘cubic’, ‘quintic’ and ‘thin_plate’.
The basis functions are:

• ‘inverse’: 1.0/sqrt((r/self.epsilon)**2 + 1)
• ‘gaussian’: exp(-(r/self.epsilon)**2)
• ‘linear’: r
• ‘cubic’: r**3
• ‘quintic’: r**5
• ‘thin_plate’: r**2 * log(r)

http://docs.scipy.org/doc/scipy-0.16.0/reference/generated/scipy.interpolate.Rbf.html

```from scipy.interpolate.rbf import Rbf  # radial basis functions
from urllib.request import urlopen

import matplotlib.pyplot as plt
import numpy as np

url = 'http://real-chart.finance.yahoo.com/table.csv?s=YHOO&amp;d=9&amp;e=17&amp;f=2015&amp;g=d&amp;a=3&amp;b=12&amp;c=1996&amp;ignore=.csv'
yahoo_csv = urlopen(url)
data_yahoo = np.genfromtxt(yahoo_csv, delimiter=',', dtype=None)
data_yahoo = data_yahoo[1:,1:]

"""
On the previous post, the data are decreasing
according to time (from 2015 to the first year).
Let's invert them.
"""

data_yahoo = np.flipud(data_yahoo)
adj_close = np.array(data_yahoo[:, 5:].flatten(), dtype=float)  # "Squeeze" the vector into 1 dimension
```

First we import the necessary packages and the Rbf function. We also obtain the dataset and get rid of the first row and column, as we saw on the previous post. After these steps, we invert the dataset, so the data will be increasing over time.

```adj_x = np.linspace(0, last, last, endpoint=True)  # Creating X axis with days.
```

Here we create the X axis to support the function. Note that applying Rbf is easy: we provide only the values of X and Y axes. Y are the interest points. We didn’t specify the ‘function’ parameter, so Rbf will use the multiquadric function.

```# Getting the first 60 days. Creating also the X axis
x_axis = np.linspace(0, 60, 500)

# Interpolating the result between the 60 days.
plt.figure()

# Plotting the original points.
plot3 = plt.plot(adj_bimes, 'ko', markersize=12)  # the original points.
```

We defined an interval to check the interpolation quality (as we did on this post). This time we took an interval of 60 days. After that we create the X axis to support this interval and plotted the original points.

```# Interpolating.
# function = 'linear':
plot3 = plt.plot(x_axis, lin_bimes, '-', label='lin')
```

Now we use Rbf. The ‘function’ argument which we use here is ‘linear’. We obtain the fit using the function rbf_adj, generated by Rbf. After that, we plot the result.

Note that we provided the label argument inside plot. With this argument, we can inform the label of a function on the plot legend.

Let’s try another function!

```# function = 'cubic':
plot3 = plt.plot(x_axis, cub_bimes, '-', label='cubic')
```

This time we use ‘cubic’ as the ‘function’ argument. We obtain the function rbf_adj and the fit cub_bimes. After that we plot the result.

```leg = plt.legend()
plt.show()
```

Finally, we put a legend on it and plot. As we said, it uses the arguments on label to label each plot.
This is the resulting plot:

This is it scientist! Today we saw how to use Rbf, another function to interpolate data. We saw also how to label functions and to put legends on a plot using them. Test Rbf using another parameters, and also another areas from the plot! Modify the colors as you like too. Please share your modifications with us!

Thanks scientist! Gigaregards!