https://matplotlib.org/cheatsheets/
Matplotlib cheatsheets — Visualization with Python
matplotlib.org
https://colab.research.google.com/drive/1zJUqC1JxKbTgCcNgqOkwIMgketocxh3O#scrollTo=T2ULPMl6gyS5
Google Colab Notebook
Run, share, and edit Python notebooks
colab.research.google.com
fig, ax = plt.subplots(1,2,figsize=[15,5])
x = range(0,10)
y = np.exp(x)
ax[0].plot(x,y,marker='o',linestyle="--",color='r') # marker,점선,색
ax[0].set_title('지수함수')
# label
ax[0].set_xlabel('x')
ax[0].set_ylabel('y',rotation=0,labelpad=30)
# 눈금 지정 (홀수)
ax[0].set_xticks(list(range(1,10,2)))
x = range(1,1000)
y = np.log(x)
ax[1].plot(x,y,marker='v',color='g')
ax[1].set_title('로그함수')
# label
ax[1].set_xlabel('x')
ax[1].set_ylabel('y',rotation=0,labelpad=30)
# 눈금 옆으로 돌리기
ax[1].tick_params(axis='x',labelrotation=45)
# 눈금 지정 (짝수)
ax[1].set_yticks(list(range(2,9,2)))
plt.show()
# 범례
fig,ax = plt.subplots()
x=np.arange(10)
ax.plot(x)
ax.plot(x**2,alpha=0.5,color='r') # alpha 투명도 0~1
# 범례 표시
ax.legend(['x','x^2'],loc='upper left')
plt.show()
x=np.arange(0,4,0.5)
plt.plot(x,x+1,'bo')
plt.plot(x,x+2,'k--')
plt.plot(x,x+3,'r^')
plt.plot(x,x**2-4,'g--')
plt.plot(x,-2*x+3,'r:')
# ax vertical line (x,y start, y end)
plt.axvline(1.0, 0.2, 0.8, color='lightgrey',linestyle='--',linewidth=2)
# ax horizontal line (x,y start,y end)
plt.axhline(4.0, 0.1, 0.9, color='brown',linestyle=':',linewidth=10)
plt.show()
x = np.arange(3)
years= ['2018','2019','2020']
Values = [100,400,900]
colors=["#5fd4d4",'#404bbd','#e096cb']
plt.barh(x,Values,color=colors) # 눕힌 막대 그래프
plt.xticks(x,years) # x 축
plt.show()
n=50
x=np.random.rand(n)
y=np.random.rand(n)
area=np.pi*(15*np.random.rand(n))**2
colors=np.random.rand(n)
plt.scatter(x,y,s=area,c=colors,alpha=0.5,cmap='viridis')
plt.colorbar()
plt.show()
# 범주형 데이터 > 막대 그래프
# 실수 데이터 > 히스토그램
import random
# Generate a random integer between 60 and 100 (inclusive).
weight = [random.randint(60, 100) for _ in range(10)]
# historgam graph
plt.hist(weight,bins=10)
plt.show()
# 오차막대 그래프 예시
import matplotlib.pyplot as plt
import numpy as np
# Sample data
x = np.arange(5) # x-values: [0, 1, 2, 3, 4]
y = [2, 4, 1, 3, 5] # y-values (mean values)
errors = [0.5, 0.8, 0.3, 0.6, 0.7] # Error values for each data point
# Create the error bar plot
plt.errorbar(x, y, yerr=errors, fmt='o-', capsize=5, color='blue')
# Customize the plot
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Error Bar Graph Example')
plt.grid(True)
# Display the plot
plt.show()
colors=['r','g','b']
wedgeprops={'width': 0.7, 'edgecolor': 'w', 'linewidth': 5}
plt.pie(ratio, labels=labels, autopct='%.1f%%', startangle=260, counterclock=False, colors=colors, wedgeprops=wedgeprops)
plt.show()
# 1. 기본 스타일 설정
plt.style.use('default')
plt.rcParams['figure.figsize'] = (4, 3)
plt.rcParams['font.size'] = 12
# 2. 데이터 준비
np.random.seed(0)
data_a = np.random.normal(0, 2.0, 1000)
data_b = np.random.normal(-3.0, 1.5, 500)
data_c = np.random.normal(1.2, 1.5, 1500)
# 3. 그래프 그리기
fig, ax = plt.subplots()
ax.boxplot([data_a, data_b, data_c])
ax.set_ylim(-10.0, 10.0)
ax.set_xlabel('Data Type')
ax.set_ylabel('Value')
plt.show()
자동 시각화도구
sweetvz
dataprep
졸면서 들어서 잘 못들었다.. 망했다..
그래도 시각화는 많이 해봐서 좀 안다.
그냥 어떤 그래프를 어떨 때 쓸 지 알고, 그거 레퍼런스 찾아서 갖다 쓰면 됨
자동 시각화도구도 써보고!
'개발공부 > SK Networks Family AI bootcamp 강의노트' 카테고리의 다른 글
16일차 [ Seaborn, EDA ] (1) | 2025.02.05 |
---|---|
15일차 [ 데이터 시각화 심화 ] (0) | 2025.02.05 |
14일차 [ 데이터 시각화 ] (0) | 2025.02.03 |
14일차 [ pandas 심화 ] (0) | 2025.02.03 |
13일차 [ 데이터분석: Pandas ] (0) | 2025.01.31 |