Skip to content

Commit 4518cf6

Browse files
committed
correct homework
1 parent 078fca4 commit 4518cf6

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

D18_matplotlib/homework.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@
33
import numpy as np
44

55
# 1. 畫出 cos 圖檔,並儲存
6-
x = np.arange(0,360)
7-
y = np.cos(x*np.pi/180.0)
8-
plt.plot(x,y, color = 'red')
6+
# x = np.arange(0,360)
7+
# y = np.cos(x*np.pi/180.0)
8+
# plt.plot(x,y, color = 'red')
9+
10+
#Correction
11+
#畫出完整的 cos 圖形
12+
x = np.arange(0, 3 * np.pi, 0.1)
13+
y_cos = np.cos(x)
14+
plt.plot(x, y_cos)
915

1016
# 照需要寫入x 軸和y軸的 label 以及title
1117
plt.xlabel("x-axis")
@@ -15,10 +21,16 @@
1521
plt.show()
1622

1723
# 2. 給定散點圖顏色
18-
X = np.random.normal(0, 1, 100)
19-
Y = np.random.normal(0, 1, 100)
20-
plt.scatter(X, Y, color = 'gold')
24+
n=1024
25+
X = np.random.normal(0, 1, n)
26+
Y = np.random.normal(0, 1, n)
2127
plt.title("Scatter plot")
28+
plt.scatter(X, Y, color = 'gold')
29+
#correction
30+
T = np.arctan2(Y,X)
31+
plt.scatter(X,Y, s=75, c=T, alpha=.5)
32+
plt.xlim(-1.5,1.5)
33+
plt.ylim(-1.5,1.5)
2234

2335
# 如果要存成圖形檔:
2436
# 把 pyplot.show() 換成下面這行:

0 commit comments

Comments
 (0)