본문 바로가기

Python/시각화

시각화_02. matplotlib

반응형
day4_시각화1

Matplotlib 시각화

In [75]:
import numpy as np
import pandas as pd

matplotlib 임포트와 매직명령어

In [76]:
import matplotlib
import matplotlib.pyplot as plt
In [77]:
matplotlib.__version__
Out[77]:
'3.1.0'

matplotlib 매직 명령어

  • 자동으로 리사이징 옵션 지정
In [78]:
%matplotlib inline

Figure 객체 생성하기

  • Figure : 도식. 그래프가 삽입되는 객체
  • var = plt.figure()
In [79]:
fig = plt.figure()
<Figure size 432x288 with 0 Axes>
In [80]:
type(fig)
Out[80]:
matplotlib.figure.Figure

plot 객체 생성하기

  • figVar, plt.plot(xData,yData,label=lebelName) : figure에 플랏 생성하기
  • plt.xlabel(X축)
  • plt.ylabel(Y축)
  • plt.title(제목)
  • plt.legend() : 범례 표시
  • plt.show() : plot 다시 그리기
In [82]:
fig = plt.figure()
x = [0,1,2,3,4]
y = [10,25,30,8,30]
fig, plt.plot(x,y,label='Test')
plt.xlabel('x axis')
plt.ylabel('y axis')
plt.title('Main Title')
plt.legend()
plt.show()

Plot - 다중 그래프

  • figure 생성
  • x축 데이타 생성 : np.linspace(start, end, count)
  • 다중 그래프 추가 : plt.plot(xData, yData, label)
  • 범례표시 : plt.legend()
  • 제목 표시 : plt.title(제목)
  • plt.show()
In [84]:
# x축 데이타 생성 
x = np.linspace(0, 2, 100)
x[0:10]
Out[84]:
array([0.        , 0.02020202, 0.04040404, 0.06060606, 0.08080808,
       0.1010101 , 0.12121212, 0.14141414, 0.16161616, 0.18181818])
In [85]:
# figure 생성 
fig4 = plt.figure()
<Figure size 432x288 with 0 Axes>

색상

  plt.plot(x,y, c='colorValue')
  plt.plot(x,y, color='colorValue')
  : colorValue - 16진수색상값 #000000 ~ #FFFFFF
               - colorname : black ~
  ``` 색상값 참조 https://www.w3schools.com/colors/colors_names.asp

'b' blue 'g' green 'r' red 'c' cyan 'm' magenta 'y' yellow 'k' black 'w' white ```

In [86]:
# 3개의 그래프 추가 
fig4, plt.plot(x, x, label='graph1', c='r')
fig4, plt.plot(x, x**2, label='graph2', c='g')
fig4, plt.plot(x, x**3, label='graph3' , color='black')
fig4, plt.title("Multi Graph Plot")
fig4, plt.legend()
fig4, plt.show()
Out[86]:
(<Figure size 432x288 with 0 Axes>, None)
In [ ]:
 
반응형

'Python > 시각화' 카테고리의 다른 글

시각화_05. 워드클라우드02  (0) 2019.08.26
시각화_04. 워드클라우드01  (0) 2019.08.26
시각화_03  (0) 2019.08.26
시각화_01. seaborn  (0) 2019.08.26