multiplot tutorial

Although the forthcoming inline plots are static, running this code in a Python shell will produce interactive matplotlib windows.


In [1]:
import pandas as pd
import numpy as np
import scipy.signal as signal
from multiplot import PandasPlot, NumpyPlot
%matplotlib inline

Generate a set of sample signals.


In [2]:
samp_freq = 1000 # Hz
duration = 5 # seconds
first_signal_freq =1 # Hz

signals = []
labels = []

for x in xrange(1,6):
    signal_freq = first_signal_freq * x
    time_points = np.arange(0, duration, 1/float(samp_freq))
    sig = np.sin(2 * np.pi * signal_freq * time_points)
    sig_label = "Ch %d" %(x-1)
    labels.append(sig_label)
    signals.append(sig)

df = pd.DataFrame(np.transpose(signals), columns=labels)
nump = np.array(signals)

Note that PandasPlot expects a DataFrame where each series is a column, whereas NumpyPlot expects an array where each series is a row.


In [3]:
print 'DataFrame: ', df.shape
print 'Numpy array: ', nump.shape


DataFrame:  (5000, 5)
Numpy array:  (5, 5000)

In [4]:
PandasPlot(df)


Out[4]:
<multiplot.PandasPlot at 0x7fb123b460d0>

In [5]:
NumpyPlot(nump, labels=labels) # if labels aren't supplied, 'Ch x' labels are auto-generated


Out[5]:
<multiplot.NumpyPlot at 0x7fb11e18dfd0>

Reduce number of channels displayed at once


In [6]:
PandasPlot(df, num_display_chans=2)


Out[6]:
<multiplot.PandasPlot at 0x7fb11a492dd0>

Reduce number of samples displayed at once


In [7]:
PandasPlot(df, num_display_samps=2000)


Out[7]:
<multiplot.PandasPlot at 0x7fb119fe9f90>

Highlight segments of the signals


In [8]:
highlights = {'Ch 0': [[2000, 3000]],
              'Ch 2': [[1000, 2000], [3000, 4000]],
              'Ch 4': [[2000, 3000]]}

PandasPlot(df, highlights=highlights)


Out[8]:
<multiplot.PandasPlot at 0x7fb1199d8210>