파이썬 시각화

Finance를 위한 Python 입문

Adina Howe

Professor

Matplotlib: 시각화 패키지

Matplotlib 갤러리를 더 보려면 이 링크를 클릭하십시오.

matplotlib

Finance를 위한 Python 입문

matplotlib.pyplot - 다양한 플로팅 함수

import matplotlib.pyplot as plt
Finance를 위한 Python 입문

matplotlib.pyplot - 다양한 플로팅 함수

  • plt.plot()

    • 그릴 데이터 인수를 받습니다
  • plt.show()

    • 플롯을 화면에 표시합니다
Finance를 위한 Python 입문

pyplot으로 그리기

import matplotlib.pyplot as plt
plt.plot(months, prices)
plt.show()
Finance를 위한 Python 입문

플롯 결과

간단한 플롯

Finance를 위한 Python 입문

빨간 실선

import matplotlib.pyplot as plt
plt.plot(months, prices, color = 'red')
plt.show()
Finance를 위한 Python 입문

플롯 결과

빨간 선

Finance를 위한 Python 입문

점선

import matplotlib.pyplot as plt
plt.plot(months, prices, color = 'red', linestyle = '--')
plt.show()
Finance를 위한 Python 입문

플롯 결과

점선

Finance를 위한 Python 입문

색상과 선 스타일

color
'green' 녹색
'red' 빨강
'cyan' 청록
'blue' 파랑
linestyle
'-' 실선
'--' 점선
'-.' 일점쇄선
':' 점선(점)

색상과 선 스타일에 대한 자세한 문서는 여기에서 확인하실 수 있습니다.

Finance를 위한 Python 입문

레이블과 제목 추가

import matplotlib.pyplot as plt
plt.plot(months, prices, color = 'red', linestyle = '--')

# Add labels
plt.xlabel('Months')
plt.ylabel('Consumer Price Indexes, $')
plt.title('Average Monthly Consumer Price Indexes')

# Show plot
plt.show()
Finance를 위한 Python 입문

플롯 결과

레이블 추가된 플롯

Finance를 위한 Python 입문

선 추가하기

import matplotlib.pyplot as plt
plt.plot(months, prices, color = 'red', linestyle = '--')

# adding an additional line
plt.plot(months, prices_new, color = 'green', linestyle = '--') 

plt.xlabel('Months')
plt.ylabel('Consumer Price Indexes, $')
plt.title('Average Monthly Consumer Price Indexes')
plt.show()
Finance를 위한 Python 입문

플롯 결과

두 개의 선

Finance를 위한 Python 입문

산점도

import matplotlib.pyplot as plt
plt.scatter(x = months, y = prices, color = 'red')
plt.show()
Finance를 위한 Python 입문

산점도 결과

산점도

Finance를 위한 Python 입문

연습해 봅시다!

Finance를 위한 Python 입문

Preparing Video For Download...