본문 바로가기

컴퓨터 마스터되기

[matplotlib] 플롯 그리기

먼저 라이브러리를 불러오자

import matplotlib.pyplot as plt
import seaborn as sns

이전 글에 이어서 iris 데이터셋을 학습한다.

iris 데이터셋을 train이라는 어레이에 저장해 둔상태다.

train_y = train['variety']
train_x = train.drop(['variety'], axis=1)

 

plt.figure(figsize = (15,15))
sns.pairplot(train_x)
plt.show()

그렇가면 각 변수별 갯수는 어떻게 될까? 

이건 아래의 코드를 실행해보

fig, axes = plt.subplots(2, 2, figsize=(20,20)) #사이즈에 맞게 변경

#index명 입력 추가로 늘려주면서 위치 지정해줘야해
sns.countplot(x = train_x['sepal.length'], ax=axes[0][0]).set_title('sepal.length')
sns.countplot(x = train_x['sepal.width'], ax=axes[0][1]).set_title('sepal.width')
sns.countplot(x = train_x['petal.length'], ax=axes[1][0]).set_title('petal.length')
sns.countplot(x = train_x['petal.width'], ax=axes[1][1]).set_title('petal.width')

plt.show()