https://matplotlib.org/

Untitled

πŸ“‰ 차트 μœ ν˜•

  1. μ„  κ·Έλž˜ν”„(Line Plot): λ°μ΄ν„°μ˜ λ³€ν™”λ₯Ό μ„ μœΌλ‘œ μ—°κ²°ν•˜μ—¬ μ‹œκ°ν™”ν•©λ‹ˆλ‹€.
  2. λ§‰λŒ€ κ·Έλž˜ν”„(Bar Chart): λ²”μ£Όν˜• λ°μ΄ν„°μ˜ 값을 λ§‰λŒ€λ‘œ ν‘œν˜„ν•©λ‹ˆλ‹€.
    1. https://matplotlib.org/stable/gallery/lines_bars_and_markers/barchart.html#sphx-glr-gallery-lines-bars-and-markers-barchart-py
    2. https://matplotlib.org/stable/gallery/lines_bars_and_markers/barh.html
  3. νžˆμŠ€ν† κ·Έλž¨(Histogram): μ—°μ†ν˜• λ°μ΄ν„°μ˜ 뢄포λ₯Ό κ΅¬κ°„λ³„λ‘œ λ§‰λŒ€λ‘œ λ‚˜νƒ€λƒ…λ‹ˆλ‹€.
    1. https://matplotlib.org/stable/gallery/statistics/hist.html
    2. https://matplotlib.org/stable/gallery/mplot3d/hist3d.html
    3. https://numpy.org/doc/stable/reference/generated/numpy.histogram.html#numpy.histogram
  4. 산점도(Scatter Plot): 두 λ³€μˆ˜μ˜ 관계λ₯Ό 점으둜 ν‘œν˜„ν•©λ‹ˆλ‹€.
  5. 파이 차트(Pie Chart): 전체 λŒ€λΉ„ 각 λΆ€λΆ„μ˜ λΉ„μœ¨μ„ μ›ν˜•μœΌλ‘œ λ‚˜νƒ€λƒ…λ‹ˆλ‹€.
  6. λ°•μŠ€ν”Œλ‘―(Box Plot): λ°μ΄ν„°μ˜ 뢄포와 μ΄μƒμΉ˜λ₯Ό μ‹œκ°ν™”ν•©λ‹ˆλ‹€.
  7. μ˜μ—­ κ·Έλž˜ν”„(Area Plot): μ„  κ·Έλž˜ν”„ μ•„λž˜ μ˜μ—­μ„ μ±„μ›Œμ„œ ν‘œν˜„ν•©λ‹ˆλ‹€.
  8. 히트맡(Heatmap): κ°’μ˜ 크기λ₯Ό μƒ‰μƒμœΌλ‘œ ν‘œν˜„ν•˜λŠ” 2차원 κ·Έλž˜ν”„μž…λ‹ˆλ‹€.

πŸ§‘β€πŸ’» μ‹€ 데이터λ₯Ό μ΄μš©ν•œ 차트(Histograms) 그리기

image.png

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt # chart 그리기
import matplotlib.font_manager as fm # font μ„€μ •

######## ν•œκΈ€ 폰트 μ‚¬μš©μ„ μœ„ν•œ μ„€μ • ######## 
font_path = "C:/Windows/Fonts/gulim.ttc"  # μ‚¬μš©ν•  ν•œκΈ€ 폰트 경둜
font_prop = fm.FontProperties(fname=font_path, size=12) # 폰트 속성 객체 생성
plt.rcParams['axes.unicode_minus'] = False  # λ§ˆμ΄λ„ˆμŠ€ 기호
plt.rcParams['font.family'] = font_prop.get_name()  # matplotlib μ „μ—­ 폰트 μ„€μ • 

########## μ•”ν˜Έν™”ν 일일 수읡λ₯  νžˆμŠ€ν† κ·Έλž¨ ##########
# - BTC : λΉ„νŠΈμ½”μΈ
# - ETH : 이더리움
# - LTC : λΌμ΄νŠΈμ½”μΈ
# - 일일 수읡λ₯  : (였늘 μ’…κ°€ - μ–΄μ œ μ’…κ°€) / μ–΄μ œ μ’…κ°€ * 100

# .csv 파일 뢈러였기
df = pd.read_csv('./data/crypto_daily_returns.csv')

# λΉ„νŠΈ `코인`κ³Ό `이더리움` κ·Έλž˜ν”„ 그리기
plt.hist(df['BTC'], bins=30, alpha=0.5, label='BTC')
plt.hist(df['ETH'], bins=30, alpha=0.5, label='ETH')
plt.xlabel('Daily Returns')
plt.ylabel('Frequency')
plt.title('μ•”ν˜Έν™”ν 일일 수읡λ₯ ')
plt.legend()

plt.show()

image.png