AI 보안 데이터 리터러시_Matplotlib

거부기·2022년 6월 10일
1

📊 KOCW

목록 보기
7/8
post-thumbnail

데이터 시각화 라이브러리_matplotlib

import warnings
warnings.filterwarnings('ignore')
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as pit

iris = sns.load_dataset('iris')
iris.head()

df = iris.groupby(iris['species']).mean()# 종 별로 평균값을 보여줌
df.plot() # 선 그래프

df.plot.bar() # 막대 그래프

df2 = iris.groupby(iris['species']).median() # 중위수로 그래프
df2

df2.plot()

df2.plot.bar()

df2.plot.bar(rot = 0 ) # 그래프의 종 이름이 가로로 편하게 보임

iris.plot.scatter(x='sepal_length', y='sepal_width') # x,y 정보 제공하여 산점도 

x = np.where(iris['species'] == 'setosa','red','green') # 종에 따라 다르게 점 색 표시, true면 red, false면 gree
iris.plot.scatter(x='sepal_length', y='sepal_width', c=x)

# 중첩 if문 처럼 작성
x = np.where(iris['species'] == 'setosa','red',
    np.where(iris['species'] == 'versicolor','green','blue'))
iris.plot.scatter(x='sepal_length', y='sepal_width', c=x)

iris.plot.scatter(x='petal_length', y='petal_width', c=x) # 선형관계가 위보다 잘보임

tips = sns.load_dataset('tips')
tips.head()

tips.groupby(tips['time']).mean() # 시간대별

df3 = tips.groupby(tips['day']).mean() # 요일별
df3.plot()

df3.plot.bar()

df3.plot.bar(rot=0)

tips.corr()

tips.plot.scatter(x = 'total_bill', y ='tip')

x = np.where(tips['day'] == 'Thur','red',
    np.where(tips['day'] == 'Fri','orange',
    np.where(tips['day'] == 'Sat','green','blue')))
tips.plot.scatter(x = 'total_bill', y ='tip', c = x)

profile
느리지만 확실하게

0개의 댓글