forked from rougier/numpy-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslices.py
More file actions
70 lines (51 loc) · 1.51 KB
/
Copy pathslices.py
File metadata and controls
70 lines (51 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import numpy as np
import matplotlib.pyplot as plt
def show_slice(Z, name):
rows,cols = Z.shape
fig = plt.figure(figsize=(cols/4.,rows/4.), dpi=72)
ax = plt.subplot(111)
A = np.arange(rows*cols).reshape(rows,cols)
plt.imshow(Z, cmap='Purples', extent=[0,cols,0,rows],
vmin=0, vmax=1, interpolation='nearest', origin='upper')
plt.xticks([]), plt.yticks([])
for pos in ['top', 'bottom', 'right', 'left']:
ax.spines[pos].set_edgecolor('k')
ax.spines[pos].set_alpha(.25)
plt.savefig('../figures/%s' % name, dpi=72)
#plt.show()
rows,cols = 5, 9
Z = np.zeros((rows,cols))+.1
show_slice(Z, 'slice-Z.png')
Z = np.zeros((rows,cols))+.1
Z[...] = 1
show_slice(Z, 'slice-Z[...].png')
Z = np.zeros((rows,cols))+.1
Z[:,::2] = 1
show_slice(Z, 'slice-Z[:,::2].png')
Z = np.zeros((rows,cols))+.1
Z[::2,:] = 1
show_slice(Z, 'slice-Z[::2,:].png')
Z = np.zeros((rows,cols))+.1
Z[1,1] = 1
show_slice(Z, 'slice-Z[1,1].png')
Z = np.zeros((rows,cols))+.1
Z[:,0] = 1
show_slice(Z, 'slice-Z[:,0].png')
Z = np.zeros((rows,cols))+.1
Z[0,:] = 1
show_slice(Z, 'slice-Z[0,:].png')
Z = np.zeros((rows,cols))+.1
Z[2:,2:] = 1
show_slice(Z, 'slice-Z[2:,2:].png')
Z = np.zeros((rows,cols))+.1
Z[:-2,:-2] = 1
show_slice(Z, 'slice-Z[:-2,:-2].png')
Z = np.zeros((rows,cols))+.1
Z[2:4,2:4] = 1
show_slice(Z, 'slice-Z[2:4,2:4].png')
Z = np.zeros((rows,cols))+.1
Z[::2,::2] = 1
show_slice(Z, 'slice-Z[::2,::2].png')
Z = np.zeros((rows,cols))+.1
Z[3::2,3::2] = 1
show_slice(Z, 'slice-Z[3::2,3::2].png')