Plotly's Python library is free and open source! Get started by dowloading 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.tools as tools
from plotly.tools import FigureFactory as FF
import numpy as np
import pandas as pd
import scipy
To properly visualize our data and normalization, let us import a dataset of Apple Stock prices in 2014:
apple_data = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2014_apple_stock.csv')
df = apple_data[0:10]
table = FF.create_table(df)
py.iplot(table, filename='apple-data-sample')
Normalize a dataset by dividing each data point by a constant, such as the standard deviation of the data.
data = apple_data['AAPL_y']
data_norm_by_std = [number/scipy.std(data) for number in data]
trace1 = go.Histogram(
x=data,
opacity=0.75,
name='data'
)
trace2 = go.Histogram(
x=data_norm_by_std,
opacity=0.75,
name='normalized by std = ' + str(scipy.std(data)),
)
fig = tools.make_subplots(rows=2, cols=1)
fig.append_trace(trace1, 1, 1)
fig.append_trace(trace2, 2, 1)
fig['layout'].update(height=600, width=800, title='Normalize by a Constant')
py.iplot(fig, filename='apple-data-normalize-constant')
This is the format of your plot grid: [ (1,1) x1,y1 ] [ (2,1) x2,y2 ]
Normalize a dataset by dividing each data point by the norm of the dataset.
data_norm_to_0_1 = [number/scipy.linalg.norm(data) for number in data]
trace1 = go.Histogram(
x=data,
opacity=0.75,
name='data',
)
trace2 = go.Histogram(
x=data_norm_to_0_1,
opacity=0.75,
name='normalized to [0,1]',
)
fig = tools.make_subplots(rows=2, cols=1)
fig.append_trace(trace1, 1, 1)
fig.append_trace(trace2, 2, 1)
fig['layout'].update(height=600, width=800, title='Normalize to [0,1]')
py.iplot(fig, filename='apple-data-normalize-0-1')
This is the format of your plot grid: [ (1,1) x1,y1 ] [ (2,1) x2,y2 ]
Normalize a dataset to an interval [a, b] where a, b are real numbers.
a = 10
b = 50
data_norm_to_a_b = [(number - a)/(b - a) for number in data]
trace1 = go.Histogram(
x=data,
opacity=0.75,
name='data',
)
trace2 = go.Histogram(
x=data_norm_to_a_b,
opacity=0.75,
name='normalized to [10,50]',
)
fig = tools.make_subplots(rows=2, cols=1)
fig.append_trace(trace1, 1, 1)
fig.append_trace(trace2, 2, 1)
fig['layout'].update(height=600, width=800, title='Normalize to [10,50]')
py.iplot(fig, filename='apple-data-normalize-a-b')
This is the format of your plot grid: [ (1,1) x1,y1 ] [ (2,1) x2,y2 ]
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_Normalization.ipynb', 'python/normalization/', 'Normalization | plotly',
'Learn how to normalize data by fitting to intervals on the real line and dividing by a constant',
title='Normalization in Python. | plotly',
name='Normalization',
language='python',
page_type='example_index', has_thumbnail='false', display_as='mathematics', order=2,
ipynb= '~notebook_demo/103')
Collecting git+https://github.com/plotly/publisher.git Cloning https://github.com/plotly/publisher.git to /var/folders/ld/6cl3s_l50wd40tdjq2b03jxh0000gp/T/pip-cIVPBZ-build Installing collected packages: publisher Found existing installation: publisher 0.10 Uninstalling publisher-0.10: Successfully uninstalled publisher-0.10 Running setup.py install for publisher ... - done Successfully installed publisher-0.10
/Users/brandendunbar/Desktop/test/venv/lib/python2.7/site-packages/IPython/nbconvert.py:13: ShimWarning: The `IPython.nbconvert` package has been deprecated. You should import from nbconvert instead. "You should import from nbconvert instead.", ShimWarning) /Users/brandendunbar/Desktop/test/venv/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? '