티스토리 뷰

문제 1

  • Iris 데이터의 4가지 속성의 히스토그램을 2X2 모양의 서브플롯으로 표시하시오.





문제 2

  • 아래는 밤하늘의 별모양을 흉내낸 것이다.
  • 여기서 vmax=10, cmap='gray_r' 의 효과를 설명하시오.


Untitled18
In [10]:
import numpy as np
import matplotlib.pyplot as plt

star = np.random.randint(1000, size=[200,200])
plt.imshow(star, vmax=10, cmap='gray_r')
plt.colorbar()
Out[10]:
<matplotlib.colorbar.Colorbar at 0x2d4607d4400>
























정답

Untitled19

1번

In [1]:
import numpy as np
import matplotlib.pyplot as plt

f = open('iris.csv')

head=f.readline()

labels = ['Iris-setosa', 'Iris-versicolor', 'Iris-virginica']
data=[]

for line in f:
    l = line.strip().split(',')
    l[:4]=[float(i) for i in l[:4]]
    l[4] = labels.index(l[4])
    
    data.append(l)
    
f.close()

iris = np.array(data)
In [2]:
fig = plt.figure(figsize=[10,8])
fig.suptitle('IRIS', fontsize=20) 

plt.subplot(2,2,1)
plt.title('sepal length') 
plt.hist(iris[:,0]) 

plt.subplot(2,2,2) 
plt.title('sepal width')
plt.hist(iris[:,1])

plt.subplot(2,2,3)
plt.title('petal length')
plt.hist(iris[:,2])

plt.subplot(2,2,4)
plt.title('petal width')
plt.hist(iris[:,3])
Out[2]:
(array([41.,  8.,  1.,  7.,  8., 33.,  6., 23.,  9., 14.]),
 array([0.1 , 0.34, 0.58, 0.82, 1.06, 1.3 , 1.54, 1.78, 2.02, 2.26, 2.5 ]),
 <a list of 10 Patch objects>)

2번

gray_r은 흰색부터 검정색까지의 그라데이션을 의미한다. randint=1000이라고 했기 때문에 200x200행렬 안에는 0~999까지의 랜덤한 숫자들이 들어있다. 그리고 vmax를 10으로 줌으로써 가장 작은 값인 0이 흰색이 되고 10 이상의 모든 숫자들은 검정색으로 분류된다. 10 이하의 숫자는 극히 일부분 이므로 그림속에 검정색이 아닌 색들이 거의 안보인다.


'beginner > 파이썬 퀴즈' 카테고리의 다른 글

파이썬 기초 퀴즈_9  (0) 2019.03.09
파이썬 기초 퀴즈_8  (0) 2019.03.08
파이썬 기초 퀴즈_7  (0) 2019.03.07
파이썬 기초 퀴즈_6  (0) 2019.03.06
파이썬 기초 퀴즈_5  (0) 2019.03.05
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
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
글 보관함