Plotly's Python library is free and open source! Get started by downloading the client and reading the primer.
You can set up Plotly to work in online or offline mode, or in jupyter notebooks.
We also have a quick-reference cheatsheet (new!) to help you get started!
import plotly.plotly as py
import plotly.graph_objs as go
import plotly.figure_factory as ff
import numpy as np
import pandas as pd
import scipy
from scipy import signal
Let us import some stock data to apply convolution on.
stock_data = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/stockdata.csv')
df = stock_data[0:15]
table = ff.create_table(df)
py.iplot(table, filename='stockdata-peak-fitting')
Convolution
is a type of transform that takes two functions f
and g
and produces another function via an integration. In particular, the convolution $(f*g)(t)$ is defined as:
We can use convolution in the discrete case between two n-dimensional arrays.
sample = range(15)
saw = signal.sawtooth(t=sample)
data_sample = list(stock_data['SBUX'][0:100])
data_sample2 = list(stock_data['AAPL'][0:100])
x = list(range(len(data_sample)))
y_convolve = signal.convolve(saw, data_sample2)
x_convolve = list(range(len(y_convolve)))
trace1 = go.Scatter(
x = x,
y = data_sample,
mode = 'lines',
name = 'SBUX'
)
trace2 = go.Scatter(
x = x,
y = data_sample2,
mode = 'lines',
name = 'AAPL'
)
trace3 = go.Scatter(
x = x_convolve,
y = y_convolve,
mode = 'lines',
name = 'Convolution'
)
data = [trace1, trace2, trace3]
py.iplot(data, filename='convolution-of-two-signals')
from IPython.display import display, HTML
display(HTML('<link href="//fonts.googleapis.com/css?family=Open+Sans:600,400,300,200|Inconsolata|Ubuntu+Mono:400,700" rel="stylesheet" type="text/css" />'))
display(HTML('<link rel="stylesheet" type="text/css" href="http://help.plot.ly/documentation/all_static/css/ipython-notebook-custom.css">'))
! pip install git+https://github.com/plotly/publisher.git --upgrade
import publisher
publisher.publish(
'python-Convolution.ipynb', 'python/convolution/', 'Convolution | plotly',
'Learn how to perform convolution between two signals in Python.',
title='Convolution in Python | plotly',
name='Convolution',
language='python',
page_type='example_index', has_thumbnail='false', display_as='signal-analysis', order=4)
Collecting git+https://github.com/plotly/publisher.git
Cloning https://github.com/plotly/publisher.git to /private/var/folders/k_/zf24qrfn2kg710j9pdrxzrz40000gn/T/pip-07Be7Z-build
Installing collected packages: publisher
Found existing installation: publisher 0.11
Uninstalling publisher-0.11:
Successfully uninstalled publisher-0.11
Running setup.py install for publisher ... done
Successfully installed publisher-0.11
You are using pip version 9.0.3, however version 10.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
/Users/chelsea/venv/venv2/lib/python2.7/site-packages/IPython/nbconvert.py:13: ShimWarning: The `IPython.nbconvert` package has been deprecated since IPython 4.0. You should import from nbconvert instead. "You should import from nbconvert instead.", ShimWarning) /Users/chelsea/venv/venv2/lib/python2.7/site-packages/publisher/publisher.py:53: UserWarning: Did you "Save" this notebook before running this command? Remember to save, always save. warnings.warn('Did you "Save" this notebook before running this command? '