Python Library Matplotlib(Visualization)
Matplotlib
- 기본 구현
x = [100, 200, 300] y = [1, 2, 3] plt.plot(x, y, '--r^') #그래프에 점선, 색상, 도형을 넣을 수 있음 color = '#ff0000' 16진수도 가능, linewidth=10 두께도 가능 plt.title('hello, world, fontsize = 20) # 타이틀 표기 plt.xlabel('hello', fontsize = 10) # X축 이름 plt.xlabel('world', fontsize = 10) # Y축 이름 # labels = ['one', 'two', 'three'] plt.savefig('sample.png') # 그래프 사진으로 저장 가능
> 선 색상 스타일 공식문서 : https://matplotlib.org/3.2.1/api/_as_gen/matplotlib.pyplot.plot.html
- numpy 활용
- 선 그래프 .plot
- 산점도 .scatter
- histogram .hist
- Pie Chart .pie
- Bar Chart .bar
x = np.linspace(0, 10, 100) y = np.sin(x) z = np.cos(x) plt.plot(x, y, label = 'sin' ) plt.plot(x, z, '-o', label='cos') plt.legend(loc=4) plt.show() # 안해줘도 무방함
랜덤 뽑기 // 랜덤뽑기는 많이 뽑을수록 평평해짐
x = [np.random.randint(1, 7) for i int range (10)] #numpy 랜덤뽑기 random.randint 정수 뽑기 말고도 검색해서 가능 plt.hist(x, bins = 11) # bins 값으로 그래프간 간격 조절 가능 plt.show()
- Plotly(https://plotly.com/python/)
댓글남기기