Skip to content

Commit 078fca4

Browse files
committed
add day18 homework
1 parent 715257a commit 078fca4

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

D18_matplotlib/homework.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import pandas as pd
2+
import matplotlib.pyplot as plt
3+
import numpy as np
4+
5+
# 1. 畫出 cos 圖檔,並儲存
6+
x = np.arange(0,360)
7+
y = np.cos(x*np.pi/180.0)
8+
plt.plot(x,y, color = 'red')
9+
10+
# 照需要寫入x 軸和y軸的 label 以及title
11+
plt.xlabel("x-axis")
12+
plt.ylabel("y-axis")
13+
plt.title("Cos graphic")
14+
plt.savefig("cos.png",dpi=300,format="png")
15+
plt.show()
16+
17+
# 2. 給定散點圖顏色
18+
X = np.random.normal(0, 1, 100)
19+
Y = np.random.normal(0, 1, 100)
20+
plt.scatter(X, Y, color = 'gold')
21+
plt.title("Scatter plot")
22+
23+
# 如果要存成圖形檔:
24+
# 把 pyplot.show() 換成下面這行:
25+
plt.savefig("Scatter.png",dpi=300,format="png")
26+
plt.show()

0 commit comments

Comments
 (0)