차트(chart)나 플롯(plot)으로 시각화하는 패키지
pip install matplotlib
%matplotlib inline : jupyter notebook 내부에 그림을 표시하는 명령어
Matplotlib 예제사이트 : http://matplotlib.org/gallery.html
import matplotlib
import matplotlib.pyplot as plt
%matplotlin inline
import os
if os.name == 'posix' :
plt.rc('font', family = 'NanumBarunGothic')
else :
plt.rc('font', family = 'NanumGothic')
한글 깨질때 설치코드
!sudo apt-get install -y fonts-nanum
!sudo fc-cache -fv
!rm ~/.cache/matplotlib -rf
실행 후 런타임 재 실행
plt.title("Line plot")
plt.plot([2,7,3,1])
plt.show()

plt.title('선그래프')
plt.plot([5,10,15,20],[1,3,7,9])
plt.show()

plt.title("Line plot")
plt.plot([2,7,3,1])
plt.show()

plt.title("사용자현황'(
plt.plot([1,2,3,4],[1,3,7,9])
plt.xlabel("주")
plt.ylabel("명")
plt.show()

plt.title("사용자현황")
plt.plot([1,2,3,4],[1,3,7,9]),c="r",
lw = 2, ls = "--", marker = "o", ms = 3, mec = "b",
mew = 3, mfc = "r")
plt.xlabel("주")
plt.ylabel("명")
plt.show()

c = 선 색깔
lw = 선 굵기
ls = 선 스타일
ms = 마커 크기
mec = 마커 선 색
mew = 마커 선 굵기
mfc - 마커 내부 색깔
plt.title("Line plot")
plt.plot([2,7,3,1])
plt.xticks([0,1,2,3],['가','나','다','라'])
plt.show()

plt.title("Line plot")
plt.plot([2,7,3,1], c = 'r', label = '별다방')
plt.plot([1,3,5,7], c = 'g', label = '콩다방')
plt.grid(True)
plt.legend()
plt.show()

그래프가 그려지는 영역
plt.figure(fizsize = (가로사이즈, 세로사이즈))
plt.figure(figsize=(3,2))
plt.plot([2,7,3,1])
plt.show()

plot.figure(figsize = (5,6))
plt.subplot(2,1,1)
plt.plot([2,7,3,1],c='r')
plt.subplot(2,1,2)
plt.plot([1,3,5,6],c='g')
plt.shoW()

plt.title("매장별 매출데이터")
plt.bar([0,1,2],[10,5,15])
plt.xticks([0,1,2],['강남구','관악구','영등포구']])
plt.xlabel("지역명")
plt.ylabel("매출")
plt.show()

plt.title("매장별 매출데이터")
city = ['서울','부산','광주','인천']
y_pos = [0,1,2,3]
data = [15,3,8,2]
plt.barh(y_pos, data, aplha=0.5)
plt.yticks(y_pos,city)
plt.show()

x = np.random.randn(100)
plt.title("히스토그램")
plt.hist(x,bins=10)
plt.show()
x = np.random.randn(100): NumPy의 randn 함수를 사용하여 평균이 0이고 표준 편차가 1인 표준 정규 분포에서 100개의 난수를 생성하여 x에 저장합니다.
plt.hist(x, bins=10): x에 저장된 데이터를 이용하여 히스토그램을 그립니다. bins=10은 히스토그램의 구간(bin)을 10개로 나누라는 의미입니다.

matplotlib.rcParams['axes.unicode_minus'] = False
plt.title("STEMP PLOT")
plt.stem([0,1,2,3,4],[10,-5,2,9,-7],'-o')
plt.show()

lbels = ['서울','부산','광주','인천']
sizes = [10,50,20,60]
colors = ['y','c','b','g']
explode = (0,0.2,0,0)
plt.pie(sizes, explode=explode, labels=labels, colors=colors,
autopct = '%1.1f%%', shadow = True, startangle = 45)
plt.show()
explode = (0,0.2,0,0): 원 그래프에서 특정 부분을 강조하기 위해 해당 부분을 얼마나 떼어내어 표시할지를 결정하는 값입니다. 여기서는 '부산' 부분을 20% 정도 떼어내어 표시하도록 설정했습니다.

np.random.seed(0)
X = np.random.randint(0,50,100)
Y = np.random.randint(0,50,100)
plt.title('Scatter Plot')
plt.scatter(X,Y)
plt.show()
np.random.seed(0): 난수 발생을 위한 시드(seed)를 설정합니다. 시드를 설정하면 같은 시드를 사용할 때마다 항상 같은 난수가 생성됩니다. 이것은 재현성을 위해 사용됩니다.
X = np.random.randint(0, 50, 100): 0부터 49까지의 범위에서 무작위로 선택된 100개의 정수로 이루어진 배열을 생성하여 X에 저장합니다.
Y = np.random.randint(0, 50, 100): 또 다른 0부터 49까지의 범위에서 무작위로 선택된 100개의 정수로 이루어진 배열을 생성하여 Y에 저장합니다.

Matplotlib을 기반으로 다양한 테마와 통계용 차트 등의 기능으 추가한 시각화 패키지
iris = sns.load_dataset("iris")
titanic = sns.load_dataset("titanic")
tips = sns.load_dataset("tips")
flights = sns.load_dataset("flights")
x = iris.petal_length.values
plt.figure(figsize = (5,3))
sns.rugplot(x)
plt.title("Rug plot")
plt.show()

sns.countplot(x="class", data=titanic)
plt.title("타이타닉호의 각 클래스별 승객수")
plt.show()

sns.jointplot(x="sepal_length", y="sepal_width", data=iris)
plt.show()

plt.figure(figsize=(5,5))
sns.pairplot(iris)
plt.show()

sns.barplot(x="day",y="total_bill",data=tips)
plt.title("요일 별, 전체 팁")
plt.show()

df = flights.pivot('month','year','passengers')
sns.heatmap(df)
plt.title('Heatmap')
plt.show()

sns.pointplot(x="day",y="total_bill",data=tips)
plt.title("요일 별 전체 팁의 Box Plot")
plt.show()

sns.boxplot(x="day",y="total_bill",data=tips)
plt.title("요일 별 전체 팁의 Box Plot")
plt.show()

sns.viloinplot(x="day",y="total_bill", data=tips)
plt.title("요일 별 전체 팁의 Violin Plot")
plt.show()

np.random.seed(0)
sns.stripplot(x="day",y="total_bill",data=tips,jitter=True)
plt.title("요일 별 전체 팁의 Strip Plot")
plt.show()

sns.swarmplot(x="day",y="total_bill",data=tips)
plt.title("요일 별 전체 팁의 Swarm Plot")
plt.show()

colab 실습
https://colab.research.google.com/drive/1bojsrgv2IV33E7BejTka63tPf0tDdVw4?usp=sharing