Skip to content

Commit 04b8295

Browse files
committed
docs: document cods
1 parent 3dbd31d commit 04b8295

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

main.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,19 @@
1717
plt.rc('ytick', labelsize=SMALL) # font size of the tick labels
1818
plt.rc('legend', fontsize=SMALL) # legend font size
1919
plt.rc('figure', titlesize=BIGGER) # font size of the figure title
20+
2021
plt.rcParams["font.family"] = "Times", "Times New Roman", "serif"
2122

2223

2324
# -------------------------------------------------------------------------
2425

2526
def save_plot():
26-
left = 0.125
27+
left = 0.2
2728
right = 0.9
2829
bottom = 0.1
2930
top = 0.9
3031
wspace = 0.2
31-
hspace = 0.21
32+
hspace = 0.1
3233

3334
plt.subplots_adjust(left, bottom, right, top, wspace, hspace)
3435
plt.savefig('results/1D_to_2D.jpg', bbox_inches='tight')
@@ -37,6 +38,8 @@ def save_plot():
3738
class RecurrencePlot(object):
3839
def __init__(self, row=2, col=2):
3940
self.signal = []
41+
42+
# config pylab config for plot
4043
self.size = '%d%d' % (row, col)
4144

4245
def set_signal(self, signal):
@@ -53,8 +56,12 @@ def recurrence_plot(self, eps=0.10, steps=3):
5356
return squareform(distance)
5457

5558
def subplot(self, x, is_signal=True, cell=1, title=None, grid=True):
56-
plt.subplot(int('%s%d' % (self.size, cell)))
57-
plt.plot(x) if is_signal else plt.imshow(x)
59+
ax = plt.subplot(int('%s%d' % (self.size, cell)))
60+
ax.grid(color='gray', linestyle='dotted', linewidth=0.5)
61+
ax.spines['top'].set_visible(False)
62+
ax.spines['right'].set_visible(False)
63+
64+
plt.plot(x, 'm', linewidth=1, ) if is_signal else plt.imshow(x)
5865
plt.title(title)
5966
plt.grid(grid)
6067

@@ -65,23 +72,21 @@ def setup_plot(self, cell=1, signal_name='Raw Signal', image_name='2D Image'):
6572

6673

6774
if __name__ == "__main__":
68-
fig = plt.figure(figsize=(8, 6))
75+
# This is an example of how to give a signal to class `RecurrencePlot`.
76+
# The input signal can be like [-1, 0.5, 1, ... 1.5].
6977

70-
rp = RecurrencePlot()
78+
fig = plt.figure(figsize=(8, 2))
79+
rp = RecurrencePlot(row=1, col=2)
7180

81+
# This is how I generated a signal with a length of 50.
7282
raw_signal = np.random.uniform(-1, 1, 50)
73-
convolved_signal = calculate_convolve(raw_signal)
74-
rp.set_signal(convolved_signal)
75-
76-
# cell value must be odd number
77-
# subplot 22(1,2)
78-
rp.setup_plot(cell=1, signal_name='First Signal', image_name='2D image for first signal')
7983

80-
raw_signal = np.random.uniform(-1, 1, 50)
84+
# Then I got the convolve signal. I finally drew it.
8185
convolved_signal = calculate_convolve(raw_signal)
8286
rp.set_signal(convolved_signal)
8387

84-
# subplot 22(3,4)
85-
rp.setup_plot(cell=3, signal_name='Second Signal', image_name='2D image for second signal')
88+
# cell value must be odd number. You can create your own `setup_plot`
89+
# subplot 11(1 | 2)
90+
rp.setup_plot(cell=1, signal_name='Input Signal', image_name='2D image of Input Signal')
8691

8792
save_plot()

results/1D_to_2D.jpg

-48.8 KB
Loading

0 commit comments

Comments
 (0)