pip install matplotlib
%matplotlib inline

import pandas as pd 
import numpy as np 

import matplotlib.pyplot as plt # as in Pycharm 
import matplotlib as plt # as in Jupyter

 

맥에서 한글 깨짐 해결방법

from matplotlib import rc 

rc('font', family='AppleGothic')
plt.rcParams['axes.unicode_minus'] = False

 

 

 

 

 

1. 선 그래프

-- 기본 그래프는 선 그래프이다.

df.plot(kind = 'line')

 

 

 

한가지 그래프로 나타내기

df.plot(y='KBS')

 

 

여러개 그래프 나타내기

df.plot(y=['KBS','JTBC'])

df[['KBS','JTBC']]

df[['KBS','JTBC']].plot()

 

 

2. 막대그래프

df.plot(kind='bar')

 

 

 

 

막대그래프 가로로 눕히기

df.plot(kind='barh')

 

 

 

스택형 막대 그래프를 생성. 즉, 각 막대는 여러 데이터 시리즈의 값을 누적하여 표시

df.plot(kind='bar', stacked=True)

 

 

 

여성 그래프 생성

df['Female'].plot(kind='bar')

 

 

3. 파이그래프

df.loc[2017].plot(kind='pie')

 

 

 

4. 히스토그램

df.plot(kind='hist', y='Height')

 

 

 

 

bins : 히스토그램에서 데이터를 나눌 구간(bins)의 수를 15개로 지정

df.plot(kind='hist', y='Height', bins = 15)

 

 

5. 박스플롯

describe() : 선택된 열의 기술 통계량을 계산

df['math score'].describe()
count    1000.00000
mean       66.08900
std        15.16308
min         0.00000
25%        57.00000
50%        66.00000
75%        77.00000
max       100.00000
Name: math score, dtype: float64

반환되는 기술 통계량

  • count: 값의 개수
  • mean: 평균
  • std: 표준편차
  • min: 최솟값
  • 25%: 제1사분위수 (하위 25%의 값)
  • 50%: 중앙값 (중앙에 위치한 값, 제2사분위수)
  • 75%: 제3사분위수 (하위 75%의 값)
  • max: 최댓값

 

박스플롯 생성

df.plot(kind = 'box', y='math score')

 

 

df.plot(kind = 'box', y=['math score', 'reading score', 'writing score'])

 

 

 

6. 산점도

df.plot(kind='scatter', x='math score', y='reading score')

 

 

df.plot(kind='scatter', x='math score', y='writing score')

'데이터 분석 > Data_visualization' 카테고리의 다른 글

[코드잇]그래프 시각화 실습문제  (0) 2024.06.04
데이터 시각화방법  (0) 2024.06.03