[Python데이터시각화] 3. Pandas를 통한 차트 그리기

지원하는 plot종류

Jupyter Notebook에서 Plot 준비

%matplotlib inline
from matplotlib import pyplot as plt

plt.rcParams['axes.unicode_minus'] = False # '-' 폰트 이슈
plt.rcParams['font.family'] = 'Malgun Gothic' # 운영체제에 맞게 쓰기

import pandas as pd

Line 타입

line1_df = pd.read_excel('data/sample-line-1.xlsx', index_col='날짜')
line1_df['체결가'].plot(kind='line', legend='False')

line2_df = pd.read_excel('data/sample-line-2.xlsx', index_col='날짜')
line2_df.plot(figsize=(7, 4))

Pie 타입

pie_df = pd.read_excel('data/sample-pie.xlsx', index_col='가수')
pie_df.iloc[:10].plot(kind='pie', y='곡수', legend=False, figsize=(5, 5))

Bar 타입

bar_df = pd.read_excel('data/sample-bar.xlsx', index_col='가수')
bar_df.plot(kind='bar', legend=False, figsize=(15,5), rot=0)

Barh 타입

barh1_df = pd.read_excel('data/sample-barh-1.xlsx', index_col='가수')
barh1_df.iloc[-10:].plot(kind='barh', legend=False)
barh2_df = pd.read_excel('data/sample-barh-2.xlsx', index_col='가수')
barh2_df.iloc[-10:].plot(kind='barh', legend=False)

Scatter 타입

scatter_df = pd.read_excel('data/sample-scatter.xlsx', index_col=0)
scatter_df.plot()
scatter_df.plot(kind='scatter', x='S&P500 - Ratio', y='KOSPI200 - Ratio', figsize=(10,10))
import seaborn as sns
plt.figure(figsize=(10, 10)) # seaborn 자체에서는 figsize를 미지원
sns.regplot(data=scatter_df, x='S&P500 - Ratio', y='KOSPI200 - Ratio') # 추세선 추가