本文整理汇总了Python中scipy.interpolate.spline方法的典型用法代码示例。如果您正苦于以下问题:Python interpolate.spline方法的具体用法?Python interpolate.spline怎么用?Python interpolate.spline使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.interpolate
的用法示例。
在下文中一共展示了interpolate.spline方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: line_plot
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import spline [as 别名]
def line_plot(self):
"""
The plot uses matplotlib library and for smoothing purposes spline method is used
:return: matplotlib plot object
"""
_x_axis = self._x()
_x_new = np.linspace(_x_axis[0], _x_axis[-1], self.no_of_points*10)
_y_smooth = spline(_x_axis, self._y(), _x_new)
plt.plot(_x_new, _y_smooth)
plt.grid(True)
plt.xlabel(str(self.x_axis).capitalize())
plt.ylabel(str(self.func).capitalize())
plt.title(str(self.func).capitalize() + " vs "+str(self.x_axis).capitalize())
return plt
示例2: periodsSplineRiskFreeInterestRate
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import spline [as 别名]
def periodsSplineRiskFreeInterestRate(options, date):
"""
params: options: 计算VIX的当天的options数据用来获取expDate
date: 计算哪天的VIX
return:shibor:该date到每个到期日exoDate的risk free rate
"""
date = datetime.strptime(date,'%Y/%m/%d')
#date = datetime(date.year,date.month,date.day)
exp_dates = np.sort(options.EXE_ENDDATE.unique())
periods = {}
for epd in exp_dates:
epd = pd.to_datetime(epd)
periods[epd] = (epd - date).days*1.0/365.0
shibor_date = datetime.strptime(shibor_rate.index[0], "%Y-%m-%d")
if date >= shibor_date:
date_str = shibor_rate.index[0]
shibor_values = shibor_rate.ix[0].values
#shibor_values = np.asarray(list(map(float,shibor_values)))
else:
date_str = date.strftime("%Y-%m-%d")
shibor_values = shibor_rate.loc[date_str].values
#shibor_values = np.asarray(list(map(float,shibor_values)))
shibor = {}
period = np.asarray([1.0, 7.0, 14.0, 30.0, 90.0, 180.0, 270.0, 360.0]) / 360.0
min_period = min(period)
max_period = max(period)
for p in periods.keys():
tmp = periods[p]
if periods[p] > max_period:
tmp = max_period * 0.99999
elif periods[p] < min_period:
tmp = min_period * 1.00001
# 此处使用SHIBOR来插值
sh = interpolate.spline(period, shibor_values, tmp, order=3)
shibor[p] = sh/100.0
return shibor
示例3: skyline_plot
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import spline [as 别名]
def skyline_plot(csv_data, output_file):
"""
Creates a skyline style plot from data on a csv_file. This csv file should
be compliant with the one generated by Tracer and is parsed by parse_csv
function.
"""
fig, ax = plt.subplots()
#x_data = list(csv_data.keys())
x_data = np.arange(len(csv_data))
median_data = np.array([x[0] for x in csv_data.values()])
lower_hpd = np.array([x[1] for x in csv_data.values()])
higher_hpd = np.array([x[2] for x in csv_data.values()])
plt.xticks(x_data, ["%.2E" % x for x in csv_data.keys()], rotation=45,
ha="right")
xnew = np.linspace(x_data.min(),x_data.max(), 200)
smooth_median = spline(x_data, median_data, xnew)
smooth_lower = spline(x_data, lower_hpd, xnew)
smooth_higher = spline(x_data, higher_hpd, xnew)
ax.plot(xnew, smooth_median, "--", color="black")
#ax.fill_between(x_data, higher_hpd, lower_hpd, facecolor="blue", alpha=0.5)
ax.plot(xnew, smooth_lower, color="blue")
ax.plot(xnew, smooth_higher, color="blue")
ax.fill_between(xnew, smooth_higher, smooth_lower, facecolor="blue", alpha=0.3)
plt.xlabel("Time")
plt.ylabel("Ne")
plt.tight_layout()
plt.savefig("%s.svg" % (output_file))
示例4: plot_density
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import spline [as 别名]
def plot_density(self, ax, num=300, **kwargs):
"""Returns a density plot on an Pyplot Axes object.
Args:
:ax: (`Axes`)
An matplotlib Axes object on which the histogram will be plot
:num: (`int`)
The number of x values the line is plotted on. Default: 300
:**kwargs:
Keyword arguments that are passed on to the pyplot.plot function.
"""
colors = []
self.build()
bin_centers = np.asarray(self._get_bin_centers())
x_new = np.linspace(bin_centers.min(), bin_centers.max(), num)
if 'color' in kwargs:
colors = kwargs['color']
del kwargs['color']
power_smooth = []
for (colname, bin_values) in self.hist_dict.items():
normed_values, ble = np.histogram(self._get_bin_centers(),
bins=self.bin_list,
weights=bin_values,
density=True
)
power_smooth.append(x_new)
power_smooth.append(spline(bin_centers, normed_values, x_new))
lines = ax.plot(*power_smooth, **kwargs)
for i, line in enumerate(lines):
if len(colors) > 0:
plt.setp(line, color=colors[i], label=list(self.hist_dict.keys())[i])
else:
plt.setp(line, label=list(self.hist_dict.keys())[i])
return lines