
%matplotlib inline : Rich output 매직 메서드(그래프, 그림, 소리 등 output), 해당 메서드 사용 시 그래프 바로 출력fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)

fig = plt.figure(figsize=(5,2))
ax1 = fig.add_subplot(1,1,1)

fig = plt.figure()
ax1 = fig.add_subplot(2,2,1)
ax2 = fig.add_subplot(2,2,2)
ax3 = fig.add_subplot(2,2,4)

fig2 = plt.figure()
ax1 = fig2.add_subplot(2,3,1)
ax2 = fig2.add_subplot(2,3,4)
ax3 = fig2.add_subplot(2,3,5)
ax4 = fig2.add_subplot(2,3,6)

subject = ['English', 'Math', 'Korean', 'Science', 'Computer']
points = [40, 90, 50, 60, 100]
fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)
ax1.bar(subject,points)

plt.xlabel('Subject')
plt.ylabel('Points')
plt.title("Yuna's Test Result")

price.plot(ax=ax, style='black')ax 사용plt.xlim(), plt.ylim() : x,y 좌표 범위 설정annotate()grid()
plt.plot() : 가장 최근에 그렸던 figure와 subplot을 그림.import numpy as np
x = np.linspace(0, 10, 100)
plt.plot(x, np.sin(x), 'o')
plt.plot(x, np.cos(x), '--', color='black')
plt.show()

plt.subplot()으로 서브플롯 추가 가능x = np.linspace(0, 10, 100)
plt.subplot(2,1,1)
plt.plot(x, np.sin(x), 'o', color='orange')
plt.subplot(2,1,2)
plt.plot(x, np.cos(x), 'orange')
plt.show()

라인 스타일 -> linestyle 뒤에 이름 넣기
색상도 지정 -> 해당 기호 뒤에 붙이면 됨.
----.:plt.plot(x, x + 0, '-g') # solid green
plt.plot(x, x + 1, '--c') # dashed cyan
plt.plot(x, x + 2, '-.k') # dashdot black
plt.plot(x, x + 3, ':r'); # dotted red


pandas.plot| 메서드 이름 | 기능 |
|---|---|
label | 그래프 범례 네임 |
ax | matplotlib subplot |
style | matplotlib 스타일 문자열) |
alpha | 그래프 투명도 (0 ~ 1) |
kind | 그래프 종류: 'line', 'bar', 'barh', 'kde' |
logy | Y축 로그 스케일 여부 |
use_index | 객체 색인 -> 눈금 이름으로 쓸 때 사용 |
rot | 눈금 이름 회전(0 ~ 360) |
xticks | x축 눈금 |
yticks | y축 눈금 |
xlim | x축 범위 제한값 : [min, max] |
ylim | y축 범위 제한값 : [min, max] |
grid | 그리드 표시 |
| 메서드 이름 | 기능 |
|---|---|
subplots | 컬럼을 서브플롯에 그림 |
sharex | subplots=True -> X축 공유, 축 범위, 눈금 연결 |
sharey | subplots=True -> Y축 공유 |
figsize | (튜플) 그래프 크기 지정 |
title | (문자열) 그래프 제목 지정 |
sort_columns | 컬럼 -> 알파벳 순서 정렬 |
data.plot(kind='bar', ax=axes[0], color='blue', alpha=1)
data.plot(kind='barh', ax=axes[1], color='red', alpha=0.3)

df = pd.DataFrame(np.random.rand(6,4), columns=pd.Index(['A','B','C','D']))
df.plot(kind='line')

1️⃣ fig = plt.figure()
2️⃣ ax1 = fig.add_subplot(1,1,1)
3️⃣ ax1.bar(x, y) 축 안에 그릴 그래프 메서드 선택, 데이터 삽입
4️⃣ grid, xlabel, ylabel으로 레이블 추가
5️⃣ plt.savefig으로 저장

sns.load_dataset을 이용해 API로 예제 데이터 다운로드 및 로드df = pd.DataFrame(tips)

df.shape : 행과 열 개수 파악

df.describe()

df.info()

df['변수명'].value_counts()

막대그래프로 수치 요약tip 컬럼 -> 성별에 대한 평균으로 나타내기

성별별 팁 평균

성별별 팁 횟수

성별에 따른 팁 액수 평균 -> 막대그래프로
x, y 지정

그래프 그리기
import matplotlib.pyplot as plt
plt.bar(x = x, height = y)
plt.ylabel('tip[$]')
plt.title('Tip by Sex')

grouped = df['tip'].groupby(df['day']).mean()
x = list(grouped.index)
y = list(grouped.values)
plt.bar(x = x, height = y)
plt.ylabel('tip[$]')
plt.title('Tip by Day')
plt.show()

sns.barplot 사용

옵션 추가

요일(day)에 따른 평균 tip 그래프

violinplot

catplot

실습 : 시간대(time)에 따른 그래프

전체 음식 가격(total_bill)에 따른 tip 데이터 시각화


numpy로 임의 데이터 생성해 그래프 그려보기
np.random.randn : 표준 정규분포에서 난수 생성cumsum() : 누적합

Seaborn

도수분포표를 그래프로!
히스토그램 그려보기


전체 결제 금액 대비 팁 비율 히스토그램

seaborn

확률 밀도 그래프

1949년-1960년도별 탑승객 예제 데이터

seaborn barplot

seaborn pointplot

seaborn lineplot

달별로 보기 위한 인자 할당

히스토그램

pivot()

히트맵 그리기
