Scipy to make the graph smoother

I try to make my graph smoother with scipy but result is a horizontal line.

Code:

import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import spline

dd = [1.0, 0.7071067811865476, 0.5, 0.3535533905932738, 0.25, 0.1767766952966369]
y = range(0,6)

dd1 = np.array(dd)
y1 = np.array(y)

xsmooth = np.linspace (dd1.max(),dd1.min(),5)
ysmooth = spline (dd1,y1,xsmooth)

plt.plot(xsmooth ,ysmooth)
plt.show()

Thanks in advance

Answers


I think you may be mixing up x and y in your code. If dd are your y-values and y are your x-values, you could perform a spline interpolation like so:

import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import spline

y = [1.0, 0.7071067811865476, 0.5, 0.3535533905932738, 0.25, 0.1767766952966369]
x = range(0,6)

y = np.array(y)
x = np.array(x)

xsmooth = np.linspace (x.min(),x.max(),20) # an x vector with more intermediate values
ysmooth = spline(x,y,xsmooth) 

plt.plot(xsmooth ,ysmooth)
plt.plot(x,y,'o')
plt.show()

Need Your Help

Release and pushViewController

iphone objective-c xcode

I have a custom view controller that I push onto my navigation stack as follows:

Creating terminal based installer/wizard

user-interface installer terminal ncurses

I would like to create a terminal based installer/wizard.