I want to use something like a 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 parameter.
If I were intent on a smooth plot, would I have to inject data to smooth it out?
You can use the 'smoothing' option within the trace object. This option takes a value between 0 and 1.3, and you have to be sure to set 'shape' to '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])
I've found that the amount of smoothing that this option gives is negligible at best though. I've had more success with using the Savitzy-Golay Filter that comes in the SciPy library. You don't need to set the 'shape' or 'smoothing' options; the filter works on the values themselves:
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])
Hope this helps!
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'))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With