반응형
시각화 셋팅¶
In [2]:
import numpy as np
import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
# 한글 폰트 패스로 지정
import matplotlib.font_manager as fm
path = 'C:\Windows\Fonts\malgunbd.ttf'
font_name = fm.FontProperties(fname=path).get_name()
plt.rc('font', family=font_name)
# 자동 사이즈 조정
%matplotlib inline
Scatter Plot¶
- fiqure 생성
- plt.sctter(xData,yData,s=Size, c=colorName, marker=markerName)
- makerName : X / O / D / s / *
In [11]:
names = ['a', 'b', 'c', 'd', 'e']
values = np.random.randint(30,50,5)
values
Out[11]:
In [12]:
plt.scatter(names, values, s=200, c='blue', marker='s')
plt.suptitle('산포도')
plt.show()
scatter plot - value 표시¶
- 총 갯수 산출 : len(xData)
- for 문 이용
- value 표시 : plt.text(xPos, yPos, value)
In [4]:
names = ['group_a', 'group_b', 'group_c', 'group_d', 'group_e']
values = np.random.randint(30,50,5)
num = len(names)
fig_s2 = plt.figure()
fig_s2, plt.scatter(names, values, color='red')
# value 표시 for문
for i in np.arange(num):
fig_s2, plt.text(names[i], values[i], values[i])
fig_s2, plt.suptitle('Scatter Plot Sample')
fig_s2, plt.show()
Out[4]:
In [16]:
x = ['a','b','c','d','e','f', 'g']
y = np.random.rand(len(x))
colorValue = np.random.rand(len(x))
fig, ax = plt.subplots()
ax.scatter(x, y, s=y*1000+70, c=colorValue )
plt.show()
Pie Plot¶
- figure 생성
- plt.pie( values, labels=labelList, autopct='%digit.pointNum%Unit')
In [21]:
# Label + Value
labelList = ['Frogs', 'Hogs', 'Dogs', 'Logs']
sizes = [15, 30, 45, 10]
fig_p1 = plt.figure()
fig_p1, plt.pie(sizes, labels=labelList, autopct='%.1f%%')
plt.show()
Pie Plot - Explode¶
- plt.pie(dataValue, explode=explodeList, labels=labels, autopct='%digit.pointNum%Unit', shadow=True, startangle=angleValue)
In [35]:
# label, value 생성
labelList = 'Frogs', 'Hogs', 'Dogs', 'Logs'
sizes = [15, 30, 45, 10]
# 파이 조각에 대한 색상 리스트
colorList=('b', 'g', 'r', 'c')
# 슬라이싱되는 값은 각각의 labelData와 연계
# explode = (0,0,0,0)
explode = (0.05, 0.1, 0.25, 0.05)
# 그림자 옵션 shadow=True
# 시작 각도 지정 startangle=angleValue
fig_p2 = plt.figure()
fig_p2, plt.pie(sizes, explode=explode, labels=labelList,
autopct='%.1f%%', shadow=True, startangle=180,
textprops={'fontsize': 14}, colors=colorList)
plt.show()
Histogram plot¶
- figure 생성
- plt.hist(dataVales, bins=number, color='colorName')
In [41]:
points = np.random.randn(1000)
fig_h1 = plt.figure()
fig_h1, plt.hist(points, bins=20, color='hotpink')
Out[41]:
Histogram + Subplot¶
- figure 생성
- figureVar, subplotVar = plt.subplots(row,col, sharey=True)
sharey=True : 간격 자동 지정
- subplotVar[index].hist(dataVales, bins=number, color='colorName')
In [39]:
n_bins = 20
x = np.random.randn(100000)
y = np.random.randn(100000)
fig_h2 = plt.figure(figsize=(12,12))
fig_h2, axs = plt.subplots(1, 2, sharey=True)
fig_h2, axs[0].hist(x, bins=n_bins, color='yellowgreen')
fig_h2, axs[1].hist(y, bins=n_bins, color='brown')
Out[39]:
데이타프레임 그래프화¶
In [ ]:
반응형
'Python > 시각화' 카테고리의 다른 글
시각화_05. 워드클라우드02 (0) | 2019.08.26 |
---|---|
시각화_04. 워드클라우드01 (0) | 2019.08.26 |
시각화_02. matplotlib (0) | 2019.08.26 |
시각화_01. seaborn (0) | 2019.08.26 |