Skip to content

Latest commit

 

History

History
145 lines (121 loc) · 4.28 KB

baseline-subtraction.md

File metadata and controls

145 lines (121 loc) · 4.28 KB
jupyter
jupytextkernelspecplotly
notebook_metadata_filtertext_representation
all
extensionformat_nameformat_versionjupytext_version
.md
markdown
1.1
1.1.1
display_namelanguagename
Python 2
python
python2
descriptiondisplay_ashas_thumbnaillanguagelayoutnameorderpage_typepermalinkthumbnail
Learn how to subtract baseline estimates from data in Python.
peak-analysis
false
python
base
Baseline Subtraction
2
example_index
python/baseline-subtraction/
/images/static-image

New to Plotly?

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!

Imports

The tutorial below imports NumPy, Pandas, SciPy and PeakUtils.

importplotly.plotlyaspyimportplotly.graph_objsasgoimportplotly.toolsastoolsimportplotly.figure_factoryasffimportnumpyasnpimportpandasaspdimportscipyimportpeakutils

Import Data

As with our baseline detection example, we will import some data on milk production by month:

milk_data=pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/monthly-milk-production-pounds.csv') time_series=milk_data['Monthly milk production (pounds per cow)'] time_series=np.asarray(time_series) df=milk_data[0:15] table=ff.create_table(df) py.iplot(table, filename='milk-production-dataframe')

Plot with Baseline

To subtract a baseline estimate from our data, it is a good idea to first we must first calculate the baseline values then plot the data with the baseline drawn in.

baseline_values=peakutils.baseline(time_series) trace=go.Scatter( x=[jforjinrange(len(time_series))], y=time_series, mode='lines', marker=dict( color='#547C66', ), name='Original Plot' ) trace2=go.Scatter( x=[jforjinrange(len(time_series))], y=baseline_values, mode='markers', marker=dict( size=3, color='#EB55BF', symbol='circle-open' ), name='Baseline' ) data= [trace, trace2] py.iplot(data, filename='milk-production-plot-with-baseline')

Baseline Subtraction

baseline_values=peakutils.baseline(time_series) trace=go.Scatter( x=[jforjinrange(len(time_series))], y=time_series, mode='lines', marker=dict( color='#547C66', ), name='Original Plot' ) trace2=go.Scatter( x=[jforjinrange(len(time_series))], y=baseline_values, mode='markers', marker=dict( size=3, color='#EB55BF', symbol='circle-open' ), name='Baseline' ) data= [trace, trace2] py.iplot(data, filename='milk-production-plot-with-baseline')
fromIPython.displayimportdisplay, HTMLdisplay(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">')) ! pipinstallgit+https://github.com/plotly/publisher.git--upgradeimportpublisherpublisher.publish( 'python-Baseline-Subtraction.ipynb', 'python/baseline-subtraction/', 'Baseline Subtraction | plotly', 'Learn how to subtract baseline estimates from data in Python.', title='Baseline Subtraction in Python | plotly', name='Baseline Subtraction', language='python', page_type='example_index', has_thumbnail='false', display_as='peak-analysis', order=2, ipynb='~notebook_demo/118')
close