我想使用像Plotly Scatter这样的东西来绘制我的数据,但是我想使线条更平滑。我能想到的唯一地方就是Mode参数。
如果我一心想要一个平滑的图,我需要注入数据来平滑它吗?
发布于 2016-08-31 04:10:03
你可以在跟踪对象中使用“平滑”选项。此选项采用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过滤器方面,我取得了更大的成功。你不需要设置‘形状’或‘平滑’选项;过滤器作用于值本身:
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])希望这能有所帮助!
发布于 2021-01-28 23:54:30
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'))https://stackoverflow.com/questions/38274102
复制相似问题