Skip to content

Commit

Permalink
Added labels to some figures
Browse files Browse the repository at this point in the history
based on feedback from Todd
  • Loading branch information
cadop committed May 4, 2020
1 parent f6f7d55 commit 7039dfb
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 16 deletions.
27 changes: 25 additions & 2 deletions seg1d/examples/ex_ecg.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
>>> plt.figure(figsize=(5,3)) # doctest: +SKIP
>>> plt.plot(refs.T) # doctest: +SKIP
>>> plt.xlabel("time in s") # doctest: +SKIP
>>> plt.ylabel("ECG in mV") # doctest: +SKIP
>>> plt.tight_layout() # doctest: +SKIP
>>> plt.show() # doctest: +SKIP
.. plot::
Expand All @@ -62,6 +65,9 @@
>>> plt.figure(figsize=(15,3)) # doctest: +SKIP
>>> plt.plot(s.t_masked.T) # doctest: +SKIP
>>> plt.xlabel("time in s") # doctest: +SKIP
>>> plt.ylabel("ECG in mV") # doctest: +SKIP
>>> plt.tight_layout() # doctest: +SKIP
>>> plt.show() # doctest: +SKIP
.. plot::
Expand All @@ -76,6 +82,9 @@
>>> plt.figure(figsize=(5,3)) # doctest: +SKIP
>>> plt.plot(refs.T) # doctest: +SKIP
>>> plt.xlabel("time in s") # doctest: +SKIP
>>> plt.ylabel("ECG in mV") # doctest: +SKIP
>>> plt.tight_layout() # doctest: +SKIP
>>> plt.show() # doctest: +SKIP
.. plot::
Expand Down Expand Up @@ -104,13 +113,16 @@
>>> plt.figure(figsize=(15,3)) # doctest: +SKIP
>>> plt.plot(res.T) # doctest: +SKIP
>>> plt.show() # doctest: +SKIP
>>> plt.xlabel("time in s") # doctest: +SKIP
>>> plt.ylabel("ECG in mV") # doctest: +SKIP
>>> plt.tight_layout() # doctest: +SKIP
>>> plt.show() # doctest: +SKIP
'''


if __name__ == "__main__":
def run():

import random
import numpy as np
Expand Down Expand Up @@ -152,10 +164,16 @@

plt.figure(figsize=(5, 3))
plt.plot(refs.T)
plt.xlabel("time in s")
plt.ylabel("ECG in mV")
plt.tight_layout()
plt.show()

plt.figure(figsize=(15, 3))
plt.plot(s.t_masked.T)
plt.xlabel("time in s")
plt.ylabel("ECG in mV")
plt.tight_layout()
plt.show()

# use only 1 reference
Expand Down Expand Up @@ -184,5 +202,10 @@

plt.figure(figsize=(15, 3))
plt.plot(res.T)
plt.xlabel("time in s")
plt.ylabel("ECG in mV")
plt.tight_layout()
plt.show()

if __name__ == "__main__":
run()
3 changes: 1 addition & 2 deletions seg1d/examples/ex_segmenter_sine.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
Then we generate some data
>>> x = np.linspace(-np.pi*2, np.pi*2, 2000) #create an array of data
>>> targ = np.sin(x) # target data from a sin function
>>> targ = np.sin(x) # target data from a sin function
>>> t_s,t_e = 200,400 # define a sub-series
To assign the data to the Segmenter, first we create an instance of it and then
Expand Down Expand Up @@ -91,6 +91,5 @@ def run():
plt.tight_layout()
plt.show()


if __name__ == '__main__':
run()
66 changes: 54 additions & 12 deletions seg1d/examples/ex_sine_noise.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
>>> # Plot the target
>>> plt.figure(figsize=(10,3)) #doctest: +SKIP
>>> plt.plot(x, targ,linewidth=4,alpha=0.5,label='Target')#doctest: +SKIP
>>> plt.xlabel('Angle [rad]')#doctest: +SKIP
>>> plt.ylabel('sin(x)')#doctest: +SKIP
>>> plt.legend()#doctest: +SKIP
>>> plt.tight_layout()#doctest: +SKIP
>>> plt.show()#doctest: +SKIP
.. plot::
Expand All @@ -53,7 +56,10 @@
>>> plt.figure(figsize=(3,3)) #doctest: +SKIP
>>> # Plot the reference
>>> plt.plot(x[t_s:t_e], refData,linewidth=4,alpha=0.5,label='Reference')#doctest: +SKIP
>>> plt.xlabel('Angle [rad]')#doctest: +SKIP
>>> plt.ylabel('sin(x)')#doctest: +SKIP
>>> plt.legend()#doctest: +SKIP
>>> plt.tight_layout()#doctest: +SKIP
>>> plt.show()#doctest: +SKIP
.. plot::
Expand Down Expand Up @@ -88,11 +94,17 @@
>>> # NOTE this is just the location, the actual reference data is shown above
>>> plt.plot(x[t_s:t_e], targ[t_s:t_e],linewidth=6,alpha=0.7,label='Reference')#doctest: +SKIP
>>> #plot all segments found
>>> seg_num = 1
>>> for seg in segments:
... st = seg[0]
... e = seg[1]
... plt.plot(x[st:e], targ[st:e],dashes=[1,1],linewidth=2,alpha=0.8,label='Segment')#doctest: +SKIP
... plt.plot(x[st:e], targ[st:e],dashes=[1,1],linewidth=2,alpha=0.8, #doctest: +SKIP
... label='Segment {}'.format(seg_num)) #doctest: +SKIP
... seg_num += 1
>>> plt.xlabel('Angle [rad]')#doctest: +SKIP
>>> plt.ylabel('sin(x)')#doctest: +SKIP
>>> plt.legend()#doctest: +SKIP
>>> plt.tight_layout()#doctest: +SKIP
>>> plt.show()#doctest: +SKIP
.. plot::
Expand Down Expand Up @@ -161,19 +173,24 @@
>>> #plot the original reference segment
>>> plt.plot(x[t_s:t_e], targ[t_s:t_e],linewidth=6,alpha=0.7,label='Reference')#doctest: +SKIP
>>> #plot all segments found
>>> seg_num = 1
>>> for seg in segments:
... s = seg[0]
... st = seg[0]
... e = seg[1]
... plt.plot(x[s:e], targ[s:e],dashes=[1,1],linewidth=2,alpha=0.8,label='Segment')#doctest: +SKIP
... plt.plot(x[st:e], targ[st:e],dashes=[1,1],linewidth=2,alpha=0.8, #doctest: +SKIP
... label='Segment {}'.format(seg_num)) #doctest: +SKIP
... seg_num += 1
>>> plt.xlabel('Angle [rad]')#doctest: +SKIP
>>> plt.ylabel('sin(x)')#doctest: +SKIP
>>> plt.legend()#doctest: +SKIP
>>> plt.tight_layout()#doctest: +SKIP
>>> plt.show()#doctest: +SKIP
.. plot::
:context: close-figs
'''

if __name__ == "__main__":
def run():

import seg1d
import numpy as np
Expand All @@ -191,10 +208,14 @@
#Plot the target
plt.figure(figsize=(10,3)) #doctest: +SKIP
plt.plot(x, targ,linewidth=4,alpha=0.5,label='Target')#doctest: +SKIP
plt.xlabel('Angle [rad]')#doctest: +SKIP
plt.ylabel('sin(x)')#doctest: +SKIP
plt.legend()#doctest: +SKIP
plt.tight_layout()#doctest: +SKIP
plt.show()#doctest: +SKIP



"""
This plot can be displayed inline with a call the ``current_figure`` tag:
Expand All @@ -213,9 +234,13 @@
refData = segnoise.add_noise(np.sin(x),snr=45)[t_s:t_e]

# Plot the reference
plt.plot(x[t_s:t_e], refData,linewidth=4,alpha=0.5,label='Reference')#doctest: +SKIP
plt.legend() # doctest: +SKIP
plt.show() # doctest: +SKIP
plt.plot(x[t_s:t_e],refData,linewidth=4,alpha=0.5,label='Reference')#doctest: +SKIP
plt.xlabel('Angle [rad]')#doctest: +SKIP
plt.ylabel('sin(x)')#doctest: +SKIP
plt.legend()#doctest: +SKIP
plt.tight_layout()#doctest: +SKIP
plt.show()#doctest: +SKIP


# Make an instance of the segmenter
s = seg1d.Segmenter()
Expand All @@ -236,12 +261,19 @@
# NOTE this is just the location, the actual reference data is shown above
plt.plot(x[t_s:t_e], targ[t_s:t_e],linewidth=2,alpha=0.7,label='Reference') # doctest: +SKIP
#plot all segments found
seg_num = 1
for seg in segments:
st = seg[0]
e = seg[1]
plt.plot(x[st:e], targ[st:e],dashes=[1,1],linewidth=2,alpha=0.8,label='Segment') # doctest: +SKIP
plt.legend() # doctest: +SKIP
plt.show() # doctest: +SKIP
plt.plot(x[st:e], targ[st:e],dashes=[1,1],linewidth=2,alpha=0.8,#doctest: +SKIP
label='Segment {}'.format(seg_num))#doctest: +SKIP
seg_num += 1
plt.xlabel('Angle [rad]')#doctest: +SKIP
plt.ylabel('sin(x)')#doctest: +SKIP
plt.legend()#doctest: +SKIP
plt.tight_layout()#doctest: +SKIP
plt.show()#doctest: +SKIP


# From the plot, it is clear there is a segment that doesn't belong.
# By accessing the Segmenter attributes, the algorithm and this error are better understood (and resolved).
Expand Down Expand Up @@ -296,9 +328,19 @@
#plot the original reference segment
plt.plot(x[t_s:t_e], targ[t_s:t_e],linewidth=2,alpha=0.7,label='Reference')#doctest: +SKIP
#plot all segments found
seg_num = 1
for seg in segments:
s = seg[0]
e = seg[1]
plt.plot(x[s:e], targ[s:e],dashes=[1,1],linewidth=2,alpha=0.8,label='Segment')#doctest: +SKIP
plt.plot(x[s:e], targ[s:e],dashes=[1,1],linewidth=2,alpha=0.8,#doctest: +SKIP
label='Segment {}'.format(seg_num))#doctest: +SKIP
seg_num += 1
plt.xlabel('Angle [rad]')#doctest: +SKIP
plt.ylabel('sin(x)')#doctest: +SKIP
plt.legend()#doctest: +SKIP
plt.tight_layout()#doctest: +SKIP
plt.show()#doctest: +SKIP


if __name__ == "__main__":
run()

0 comments on commit 7039dfb

Please sign in to comment.