관리 메뉴

HAMA 블로그

Matplotlib 예제들 본문

데이터 가시화 (d3.js , Plotly, Grafana, Kibana 등)

Matplotlib 예제들

[하마] 이승현 (wowlsh93@gmail.com) 2017. 3. 21. 17:41


line chart 

import matplotlib.pyplot as plt

xs = range(1440)
plt.plot(xs, watts)
plt.axis([0, 1440, 0, 100000])
plt.xlabel("# of 1min of day")
plt.ylabel("# of watt")
plt.show()


bar chart 

import matplotlib.pyplot as plt

xs = range(1440)
plt.bar(xs, watts)
plt.axis([0, 1440, 0, 100000])
plt.xlabel("# of 1min of day")
plt.ylabel("# of watt")
plt.show()



line chart 2 

import matplotlib.pyplot as plt import numpy as np
t = np.arange(0.0, 20.0, 1)
s = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
s2 = [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]

plt.subplot(2, 1, 1)
plt.plot(t, s)
plt.ylabel('Value')
plt.title('First chart')
plt.grid(True)

plt.subplot(2, 1, 2)
plt.plot(t, s2)
plt.xlabel('Item (s)')
plt.ylabel('Value')
plt.title('Second chart')
plt.grid(True)
plt.show()


line chart 3 


import matplotlib.pyplot as plt
radius = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
area = [3.14159, 12.56636, 28.27431, 50.26544, 78.53975, 113.09724]
square = [1.0, 4.0, 9.0, 16.0, 25.0, 36.0]
plt.plot(radius, area, label='Circle')
plt.plot(radius, square, marker='o', linestyle='--', color='r', label='Square')
plt.xlabel('Radius/Side')
plt.ylabel('Area')
plt.title('Area of Shapes')
plt.legend()
plt.show()



가끔 아래와 같이 pylab 을 볼 수 있는데 이것은 matplotlib.pyplot 과 numpy 를 합쳐놓은 것이다. 사용하지말라~

from pylab import *


Comments