Skip to content

Commit a84b38e

Browse files
authored
Python Practice
1 parent 3ced513 commit a84b38e

34 files changed

+2475
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import numpy as np
2+
import matplotlib.pyplot as plt
3+
4+
5+
plt.style.use('dark_background')
6+
# x range between 0~10, there is 100 elements in between
7+
x = np.linspace(0,10,100)
8+
fig = plt.figure()
9+
10+
#Graph title and label
11+
plt.plot(x, np.sin(x))
12+
plt.title('A Sine Curve')
13+
plt.xlabel('x')
14+
plt.ylabel('sin(x)')
15+
16+
#Save as .png file
17+
fig.savefig('my_figure10.png')
18+
19+
plt.show()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import numpy as np
2+
import matplotlib.pyplot as plt
3+
4+
5+
plt.style.use('dark_background')
6+
# x range between 0~10, there is 100 elements in between
7+
x = np.linspace(0,10,100)
8+
fig = plt.figure()
9+
10+
#element labeling
11+
plt.plot(x, np.sin(x), '-g', label='sin(x)')
12+
plt.plot(x, np.cos(x), ':b', label='cos(x)')
13+
plt.axis('equal')
14+
15+
#show the line name on the right
16+
plt.legend()
17+
18+
#Save as .png file
19+
fig.savefig('my_figure11.png')
20+
21+
plt.show()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import numpy as np
2+
import matplotlib.pyplot as plt
3+
4+
5+
plt.style.use('dark_background')
6+
7+
x = np.linspace(0,10,30)
8+
y = np.sin(x)
9+
fig = plt.figure()
10+
11+
12+
13+
#choose random dot shape to draw the points in the random location
14+
rng = np.random.RandomState(0)
15+
for marker in ['o',',','x','+','v','<','>','s','d']:
16+
plt.plot(rng.rand(5),rng.rand(5),marker, label='marker={0}'.format(marker))
17+
plt.legend()
18+
plt.xlim(0,1.8)
19+
20+
#Save as .png file
21+
fig.savefig('my_figure12.png')
22+
23+
plt.show()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import numpy as np
2+
import matplotlib.pyplot as plt
3+
4+
5+
plt.style.use('dark_background')
6+
7+
x = np.linspace(0,10,30)
8+
y = np.sin(x)
9+
fig = plt.figure()
10+
11+
12+
13+
#draw graph with the simple instance
14+
plt.subplot(3,1,1)
15+
plt.plot(x,y,'-ok',color='white')
16+
17+
plt.subplot(3,1,2)
18+
plt.plot(x, y, '-p',color='blue', markersize=15, linewidth=4, markerfacecolor='white', markeredgecolor='yellow',markeredgewidth='2')
19+
20+
plt.subplot(3,1,3)
21+
plt.scatter(x,y,marker='o')
22+
23+
#Save as .png file
24+
fig.savefig('my_figure13.png')
25+
26+
plt.show()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import numpy as np
2+
import matplotlib.pyplot as plt
3+
4+
5+
plt.style.use('dark_background')
6+
# x range between 0~10, there is 100 elements in between
7+
x = np.linspace(0,10,100)
8+
fig = plt.figure()
9+
plt.subplot(2,1,1)
10+
plt.plot(x,np.sin(x),'-')
11+
plt.subplot(2,1,2)
12+
plt.plot(x,np.cos(x),'--')
13+
14+
#Save as .png file
15+
fig.savefig('my_figure2.png')
16+
17+
plt.show()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import numpy as np
2+
import matplotlib.pyplot as plt
3+
4+
5+
plt.style.use('dark_background')
6+
# x range between 0~10, there is 100 elements in between
7+
x = np.linspace(0,10,100)
8+
fig = plt.figure()
9+
plt.subplot(2,1,1)
10+
plt.plot(x, np.sin(x))
11+
plt.subplot(2,1,2)
12+
plt.plot(x, np.cos(x))
13+
plt.subplot(2,2,1)
14+
plt.plot(x, np.sin(x))
15+
plt.subplot(2,2,2)
16+
plt.plot(x, np.cos(x))
17+
18+
#Save as .png file
19+
fig.savefig('my_figure3.png')
20+
21+
22+
plt.show()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import numpy as np
2+
import matplotlib.pyplot as plt
3+
4+
5+
plt.style.use('dark_background')
6+
# x range between 0~10, there is 100 elements in between
7+
x = np.linspace(0,10,100)
8+
fig = plt.figure()
9+
ax = plt.axes()
10+
11+
x = np.linspace(0,10,100)
12+
ax.plot(x, np.sin(x))
13+
14+
#Save as .png file
15+
fig.savefig('my_figure4.png')
16+
17+
plt.show()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import numpy as np
2+
import matplotlib.pyplot as plt
3+
4+
5+
plt.style.use('dark_background')
6+
# x range between 0~10, there is 100 elements in between
7+
x = np.linspace(0,10,100)
8+
fig = plt.figure()
9+
10+
#Different Color test
11+
plt.plot(x, np.sin(x-0), color='r')
12+
plt.plot(x, np.sin(x-1), color='#ffdd44') # 16bit rgb
13+
plt.plot(x, np.sin(x-2), color=(1.0, 0.2, 0.3)) # rgb value
14+
plt.plot(x, np.sin(x-3), color='y') # w, b, g, r, y or etc
15+
plt.plot(x, np.sin(x-4), color='blue') # blue, red, green, purple or etc
16+
plt.plot(x, np.sin(x-5), color='0.75') #color between white&black 0-1
17+
18+
#Save as .png file
19+
fig.savefig('my_figure5.png')
20+
21+
plt.show()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import numpy as np
2+
import matplotlib.pyplot as plt
3+
4+
5+
plt.style.use('dark_background')
6+
# x range between 0~10, there is 100 elements in between
7+
x = np.linspace(0,10,100)
8+
fig = plt.figure()
9+
10+
#Different type of line test
11+
plt.plot(x, x+0, linestyle='solid')
12+
plt.plot(x, x+1, linestyle='dashed')
13+
plt.plot(x, x+2, linestyle='dotted')
14+
plt.plot(x, x+3, linestyle='dashdot')
15+
16+
plt.plot(x, x+4, linestyle='-')
17+
plt.plot(x, x+5, linestyle='--')
18+
plt.plot(x, x+6, linestyle=':')
19+
plt.plot(x, x+7, linestyle='-.')
20+
21+
#Save as .png file
22+
fig.savefig('my_figure6.png')
23+
24+
plt.show()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import numpy as np
2+
import matplotlib.pyplot as plt
3+
4+
5+
plt.style.use('dark_background')
6+
# x range between 0~10, there is 100 elements in between
7+
x = np.linspace(0,10,100)
8+
fig = plt.figure()
9+
10+
#Different type of line&color test
11+
plt.plot(x, x+0, '-g')
12+
plt.plot(x, x+1, '--c')
13+
plt.plot(x, x+2, ':w')
14+
plt.plot(x, x+3, '-.r')
15+
16+
#Save as .png file
17+
fig.savefig('my_figure7.png')
18+
19+
plt.show()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import numpy as np
2+
import matplotlib.pyplot as plt
3+
4+
5+
plt.style.use('dark_background')
6+
# x range between 0~10, there is 100 elements in between
7+
x = np.linspace(0,10,100)
8+
fig = plt.figure()
9+
10+
#Different graph range or starting point
11+
plt.plot(x, np.sin(x))
12+
13+
plt.xlim(10, 0)
14+
plt.ylim(1.5,-1.5)
15+
#or
16+
#plt.axis([-1,11,-1.5,1.5])
17+
18+
#Save as .png file
19+
fig.savefig('my_figure8.png')
20+
21+
plt.show()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import numpy as np
2+
import matplotlib.pyplot as plt
3+
4+
5+
plt.style.use('dark_background')
6+
# x range between 0~10, there is 100 elements in between
7+
x = np.linspace(0,10,100)
8+
fig = plt.figure()
9+
10+
#graph size test
11+
plt.subplot(2,1,1)
12+
plt.plot(x, np.sin(x))
13+
plt.axis('tight')
14+
plt.subplot(2,1,2)
15+
plt.plot(x, np.sin(x))
16+
plt.axis('equal')
17+
18+
#Save as .png file
19+
fig.savefig('my_figure9.png')
20+
21+
plt.show()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import numpy as np
2+
import matplotlib.pyplot as plt
3+
4+
5+
plt.style.use('dark_background')
6+
# x range between 0~10, there is 100 elements in between
7+
x = np.linspace(0,10,100)
8+
fig = plt.figure()
9+
plt.plot(x,np.sin(x),'-')
10+
plt.plot(x,np.cos(x),'--')
11+
12+
#Save as .png file
13+
# fig.savefig('my_figure.png')
14+
15+
# save filetype info
16+
# print(fig.canvas.get_supported_filetypes())
17+
# {
18+
# 'eps': 'Encapsulated Postscript',
19+
# 'jpg': 'Joint Photographic Experts Group',
20+
# 'jpeg': 'Joint Photographic Experts Group',
21+
# 'pdf': 'Portable Document Format',
22+
# 'pgf': 'PGF code for LaTeX',
23+
# 'png': 'Portable Network Graphics',
24+
# 'ps': 'Postscript',
25+
# 'raw': 'Raw RGBA bitmap',
26+
# 'rgba': 'Raw RGBA bitmap',
27+
# 'svg': 'Scalable Vector Graphics',
28+
# 'svgz': 'Scalable Vector Graphics',
29+
# 'tif': 'Tagged Image File Format',
30+
# 'tiff': 'Tagged Image File Format',
31+
# 'webp': 'WebP Image Format'
32+
# }
33+
34+
plt.show()
39.1 KB
Loading
29.2 KB
Loading
17.6 KB
Loading
26.6 KB
Loading
24.2 KB
Loading
30.3 KB
Loading
35.2 KB
Loading
25.9 KB
Loading
74.9 KB
Loading
54.6 KB
Loading
26.3 KB
Loading
21.6 KB
Loading
27.5 KB
Loading

Python_Numpy Practice/Basic_Numpy.py

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import numpy as np
2+
#Check array in numpy
3+
arr = np.array([1,2,3,4,5])
4+
print(arr)
5+
print(type(arr))
6+
7+
#set up array with default zero value
8+
arr = np.zeros((3,3))
9+
print(arr)
10+
11+
#create 4 by 4 array with empty value
12+
##Since, didn't set up as 0,
13+
#random value could be in depends on the memroy location
14+
arr = np.empty((4,4))
15+
print (arr)
16+
17+
#create array filled with 1
18+
arr = np.ones((3,3))
19+
print(arr)
20+
21+
#내가 자주쓰던 배열
22+
# tmp = []
23+
# for i in range(3):
24+
# tmp.append([])
25+
# for j in range(3):
26+
# tmp[i].append(j)
27+
# print(tmp)
28+
# 출력값 : [[0, 1, 2], [0, 1, 2], [0, 1, 2]]
29+
30+
# [[]] <- 이거 개수에 따라 차원 수를 알 수 있음 (현제 2차원)
31+
32+
arr=np.arange(10)
33+
print(arr)
34+
35+
arr=np.array([[1,2,3],[4,5,6]])
36+
37+
print(arr.shape)
38+
print(arr.ndim)
39+
print(arr.dtype)
40+
arr_float = arr.astype(np.float64)
41+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import numpy as np
2+
3+
#Calculation of ndarray
4+
arr1 = np.array([[1,2],[3,4]])
5+
arr2 = np.array([[5,6],[7,8]])
6+
7+
#ndarray adding up
8+
arr_added = arr1 + arr2
9+
arr_added2 = np.add(arr1,arr2)
10+
11+
# print(arr_added)
12+
# print(arr_added2)
13+
14+
#ndarray multiply
15+
arr_mult = arr1 * arr2
16+
arr_mult2 = np.multiply(arr1, arr2)
17+
18+
# print(arr_mult)
19+
# print(arr_mult2)
20+
21+
#ndarray array slicing
22+
arr = np.array([[1,2,3],[4,5,6],[7,8,9]])
23+
# 1,2,3
24+
# 4,5,6
25+
# 7,8,9
26+
arr_sliced = arr[:2,1:3]
27+
28+
# 2,3
29+
# 5,6
30+
#arr[세로 값:가로 값]
31+
# print(arr)
32+
# print('-----------')
33+
# print(arr_sliced)
34+
35+
#앞에는 세로값, 뒤에는 가로값
36+
arr_sliced2 = arr[[0,1,2],[2,0,1]]
37+
# print(arr_sliced2)
38+
39+
40+
#Returns True or False
41+
inx = arr>3
42+
print(inx)
43+
44+
#Print if arr>3
45+
print(arr[inx])

0 commit comments

Comments
 (0)