有什么方法可以使 Plotly 散点图具有平滑的线条连接点?
Is there any way to make a Plotly scatter have smooth lines connecting points?
我想使用类似 Plotly Scatter to plot my data, but I want to make the lines smooth. The only place I could think to look is at the Mode 参数的东西。
如果我想要一个平滑的图,我是否需要注入数据来平滑它?
您可以在跟踪对象中使用 'smoothing' 选项。此选项取值介于 0 和 1.3 之间,您必须确保将 'shape' 设置为 'spline':
smoothTrace = {'type' : 'scatter', 'mode' : 'lines',
'x' : [1,2,3,4,5], 'y' : [4, 6, 2, 7, 8], 'line': {'shape': 'spline', 'smoothing': 1.3}}
plotly.offline.iplot([smoothTrace])
我发现此选项提供的平滑量最多可以忽略不计。我使用 SciPy 库中的 Savitzy-Golay 过滤器取得了更大的成功。您不需要设置 'shape' 或 'smoothing' 选项;过滤器对值本身起作用:
evenSmootherTrace = {'type' : 'scatter', 'mode' : 'lines',
'x' : scipy.signal.savgol_filter([1,2,3,4,5], 51, 3),
'y' : [4, 6, 2, 7, 8]}
plotly.offline.iplot([evenSmootherTrace])
希望对您有所帮助!
https://plotly.com/python/line-charts/
import plotly.graph_objects as go
import numpy as np
x = np.array([1, 2, 3, 4, 5])
y = np.array([1, 3, 2, 3, 1])
fig = go.Figure()
fig.add_trace(go.Scatter(x=x, y=y + 5, name="spline",
text=["tweak line smoothness<br>with 'smoothing' in line object"],
hoverinfo='text+name',
line_shape='spline'))
我想使用类似 Plotly Scatter to plot my data, but I want to make the lines smooth. The only place I could think to look is at the Mode 参数的东西。
如果我想要一个平滑的图,我是否需要注入数据来平滑它?
您可以在跟踪对象中使用 'smoothing' 选项。此选项取值介于 0 和 1.3 之间,您必须确保将 'shape' 设置为 'spline':
smoothTrace = {'type' : 'scatter', 'mode' : 'lines',
'x' : [1,2,3,4,5], 'y' : [4, 6, 2, 7, 8], 'line': {'shape': 'spline', 'smoothing': 1.3}}
plotly.offline.iplot([smoothTrace])
我发现此选项提供的平滑量最多可以忽略不计。我使用 SciPy 库中的 Savitzy-Golay 过滤器取得了更大的成功。您不需要设置 'shape' 或 'smoothing' 选项;过滤器对值本身起作用:
evenSmootherTrace = {'type' : 'scatter', 'mode' : 'lines',
'x' : scipy.signal.savgol_filter([1,2,3,4,5], 51, 3),
'y' : [4, 6, 2, 7, 8]}
plotly.offline.iplot([evenSmootherTrace])
希望对您有所帮助!
https://plotly.com/python/line-charts/
import plotly.graph_objects as go
import numpy as np
x = np.array([1, 2, 3, 4, 5])
y = np.array([1, 3, 2, 3, 1])
fig = go.Figure()
fig.add_trace(go.Scatter(x=x, y=y + 5, name="spline",
text=["tweak line smoothness<br>with 'smoothing' in line object"],
hoverinfo='text+name',
line_shape='spline'))