You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: unconverted/python/smoothing.md
+52-73
Original file line number
Diff line number
Diff line change
@@ -8,9 +8,19 @@ jupyter:
8
8
format_version: '1.1'
9
9
jupytext_version: 1.1.1
10
10
kernelspec:
11
-
display_name: Python 2
11
+
display_name: Python 3
12
12
language: python
13
-
name: python2
13
+
name: python3
14
+
language_info:
15
+
codemirror_mode:
16
+
name: ipython
17
+
version: 3
18
+
file_extension: .py
19
+
mimetype: text/x-python
20
+
name: python
21
+
nbconvert_exporter: python
22
+
pygments_lexer: ipython3
23
+
version: 3.6.7
14
24
plotly:
15
25
description: Learn how to perform smoothing using various methods in Python.
16
26
display_as: signal-analysis
@@ -25,18 +35,12 @@ jupyter:
25
35
title: Smoothing in Python | plotly
26
36
---
27
37
28
-
#### New to Plotly?
29
-
Plotly's Python library is free and open source! [Get started](https://plot.ly/python/getting-started/) by downloading the client and [reading the primer](https://plot.ly/python/getting-started/).
30
-
<br>You can set up Plotly to work in [online](https://plot.ly/python/getting-started/#initialization-for-online-plotting) or [offline](https://plot.ly/python/getting-started/#initialization-for-offline-plotting) mode, or in [jupyter notebooks](https://plot.ly/python/getting-started/#start-plotting-online).
31
-
<br>We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/python_cheat_sheet.pdf) (new!) to help you get started!
32
-
33
38
34
39
#### Imports
35
40
The tutorial below imports [NumPy](http://www.numpy.org/), [Pandas](https://plot.ly/pandas/intro-to-pandas-tutorial/), [SciPy](https://www.scipy.org/) and [Plotly](https://plot.ly/python/getting-started/).
36
41
37
42
```python
38
-
import plotly.plotly as py
39
-
import plotly.graph_objs as go
43
+
import plotly.graph_objects as go
40
44
41
45
import numpy as np
42
46
import pandas as pd
@@ -50,53 +54,59 @@ from scipy import signal
50
54
51
55
There is reason to smooth data if there is little to no small-scale structure in the data. The danger to this thinking is that one may skew the representation of the data enough to change its percieved meaning, so for the sake of scientific honesty it is an imperative to at the very minimum explain one's reason's for using a smoothing algorithm to their dataset.
52
56
57
+
In this example we use the [Savitzky-Golay Filter](https://en.wikipedia.org/wiki/Savitzky%E2%80%93Golay_filter), which fits subsequents windows of adjacent data with a low-order polynomial.
58
+
53
59
```python
60
+
import plotly.graph_objects as go
61
+
62
+
import numpy as np
63
+
import pandas as pd
64
+
import scipy
65
+
66
+
from scipy import signal
67
+
54
68
x = np.linspace(0, 10, 100)
55
69
y = np.sin(x)
56
-
y_noise = [y_item + np.random.choice([-1, 1])*np.random.random() for y_item in y]
70
+
noise =2* np.random.random(len(x)) -1# uniformly distributed between -1 and 1
In the `Triangular Moving Average`, two simple moving averages are computed on top of each other. This means that our $SMA_i$ are computed then a Triangular Moving Average $TMA_i$ is computed as:
124
+
In the `Triangular Moving Average`, two simple moving averages are computed on top of each other, in order to give more weight to closer (adjacent) points. This means that our $SMA_i$ are computed then a Triangular Moving Average $TMA_i$ is computed as:
0 commit comments