如何绘制未连接所有点的样条线>>

问题描述 投票:2回答:1

我正在尝试通过样条曲线绘制大量数据,看起来像这样。enter image description here

但是当我尝试用绘图方法完成样条时,它坚持要遍历所有这样的点enter image description here enter image description here

当第一个图像仅是数据点而第二个图像是样条线时。

我尝试的代码是

dates = [dates_arr]
x = dates.strftime("%Y-%m-%d")
y = [data_points]
xy_data = go.Scatter(x=x, y=y, mode='markers', marker=dict(size=4), 
name='AAPL')

mov_avg = go.Scatter(x=x, y=y, name="spline",text= 
["spline"],hoverinfo='text+name',line_shape='spline', line_smoothing = 1.3)    

data = [xy_data, mov_avg]  

py.iplot(data, filename='Spline fit')

#################################
first_plot_url = py.plot(data, filename='apple stock moving average', 
auto_open=True, )

有人有想法吗?

我正在尝试通过样条曲线绘制大量数据,看起来像这样。但是当我尝试用绘图方式完成样条时,样条线坚持要遍历所有点,例如...

python plotly spline
1个回答
0
投票

在第一个图像中,样条曲线是对所有数据点的近似值。在您的代码段中,spline是设置为数据点之间的行的属性。这些不一样。为了完成您想要的,您可以仔细阅读this R博客中的帖子。简而言之,建议在基本支持下使用smooth.spline,或在mgcv软件包中使用GAM函数。

© www.soinside.com 2019 - 2024. All rights reserved.