55
66from utils import calculate_convolve
77
8-
98# ----------------- Plot config -------------------------------------------
109SMALL = 8
1110MEDIUM = 10
1211BIGGER = 11
1312
14- plt .rc ('font' , size = SMALL ) # controls default text sizes
15- plt .rc ('axes' , titlesize = SMALL ) # font size of the axes title
16- plt .rc ('axes' , labelsize = MEDIUM ) # font size of the x and y labels
17- plt .rc ('xtick' , labelsize = SMALL ) # font size of the tick labels
18- plt .rc ('ytick' , labelsize = SMALL ) # font size of the tick labels
19- plt .rc ('legend' , fontsize = SMALL ) # legend font size
13+ plt .rc ('font' , size = SMALL ) # controls default text sizes
14+ plt .rc ('axes' , titlesize = SMALL ) # font size of the axes title
15+ plt .rc ('axes' , labelsize = MEDIUM ) # font size of the x and y labels
16+ plt .rc ('xtick' , labelsize = SMALL ) # font size of the tick labels
17+ plt .rc ('ytick' , labelsize = SMALL ) # font size of the tick labels
18+ plt .rc ('legend' , fontsize = SMALL ) # legend font size
2019plt .rc ('figure' , titlesize = BIGGER ) # font size of the figure title
20+
21+
2122# -------------------------------------------------------------------------
2223
24+ def save_plot ():
25+ left = 0.125
26+ right = 0.9
27+ bottom = 0.1
28+ top = 0.9
29+ wspace = 0.2
30+ hspace = 0.3
31+
32+ plt .subplots_adjust (left , bottom , right , top , wspace , hspace )
33+ plt .savefig ('result.jpg' , bbox_inches = 'tight' )
34+
2335
2436class RecurrencePlot (object ):
25- def __init__ (self , signal , row = 2 , col = 2 ):
26- self .signal = signal
37+ def __init__ (self , row = 2 , col = 2 ):
38+ self .signal = []
2739 self .size = '%d%d' % (row , col )
2840
41+ def set_signal (self , signal ):
42+ self .signal = signal
43+
2944 def recurrence_plot (self , eps = 0.10 , steps = 3 ):
3045 _2d_array = self .signal [:, None ]
3146
@@ -35,24 +50,31 @@ def recurrence_plot(self, eps=0.10, steps=3):
3550 distance [distance > steps ] = steps
3651 return squareform (distance )
3752
38- def subplot (self , x , is_signal = True , index = 1 , title = None , grid = True ):
39- plt .subplot (int ('%s%d' % (self .size , index )))
53+ def subplot (self , x , is_signal = True , cell = 1 , title = None , grid = True ):
54+ plt .subplot (int ('%s%d' % (self .size , cell )))
4055 plt .plot (x ) if is_signal else plt .imshow (x )
4156 plt .title (title )
4257 plt .grid (grid )
4358
44- def save (self ):
59+ def setup_plot (self , cell = 1 , signal_name = 'Raw Signal' , image_name = '2D Image' ):
4560 # plot with various axes scales
46- plt .figure ()
47- self .subplot (self .signal , index = 1 , title = 'Raw Signal' )
48- self .subplot (self .recurrence_plot (), is_signal = False , index = 2 , title = '2D Image' )
49- self .subplot (self .signal , index = 3 , title = 'Raw Signal' )
50- self .subplot (self .recurrence_plot (), is_signal = False , index = 4 , title = '2D Image' )
51- plt .savefig ('result.jpg' )
61+ self .subplot (self .signal , cell = cell , title = signal_name )
62+ self .subplot (self .recurrence_plot (), is_signal = False , cell = cell + 1 , title = image_name )
5263
5364
5465if __name__ == "__main__" :
55- raw_signal = np .random .uniform (- 1 , 1 , 500 )
66+ plt .figure ()
67+
68+ rp = RecurrencePlot ()
69+
70+ raw_signal = np .random .uniform (- 1 , 1 , 50 )
5671 convolved_signal = calculate_convolve (raw_signal )
57- rp = RecurrencePlot (convolved_signal )
58- rp .save ()
72+ rp .set_signal (convolved_signal )
73+ rp .setup_plot (cell = 1 )
74+
75+ raw_signal = np .random .uniform (- 1 , 1 , 50 )
76+ convolved_signal = calculate_convolve (raw_signal )
77+ rp .set_signal (convolved_signal )
78+ rp .setup_plot (cell = 3 )
79+
80+ save_plot ()
0 commit comments