https://rfriend.tistory.com/408 에 seaborn와 plot 그래프들에 대한 예제가 많이 있음 참조만 할것
In [1]:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
In [2]:
data = np.random.randn(50).cumsum()
data
Out[2]:
array([-1.70416886, -2.20382106, -2.70563343, -4.28915986, -3.9987641 , -4.24362761, -5.27902219, -8.15694697, -7.9827752 , -7.80333919, -5.88645842, -3.6525847 , -5.13716405, -5.36678818, -4.97623099, -4.97469689, -5.22442605, -5.8177351 , -5.72661712, -5.74939913, -5.29489462, -5.4561586 , -3.56746048, -4.85725539, -3.78936864, -4.3710527 , -3.49514061, -3.20631578, -2.6979869 , -1.33493817, -0.73486575, -1.65087301, -0.9595155 , -0.56353054, -0.71384063, 0.17522287, 2.34517273, 3.49580553, 3.45509115, 2.51787639, 4.51080854, 5.46423596, 5.47276448, 5.17562425, 5.09205091, 5.49113898, 5.18362845, 4.25744781, 4.88338098, 5.80335486])
In [3]:
plt.plot(data)
plt.show()
In [4]:
plt.subplot(3,2,1)
plt.subplot(3,2,2)
plt.subplot(3,2,3)
plt.subplot(3,2,4)
plt.subplot(3,2,5)
plt.show()
#subplot(행,열,위치)
In [5]:
hist_data=np.random.randn(100)
scat_data=np.arange(30)
In [6]:
plt.subplot(2,2,1)
plt.plot(data)
plt.subplot(2,2,2)
plt.hist(hist_data,bins=20) #bins는 몇개로 분할할지를 알려주는것 보통 data의 최소값과 최대값을 기준으로 나눈다.
plt.subplot(2,2,3)
plt.scatter(scat_data,np.arange(30)+3 * np.random.randn(30))
plt.show()
색상:b(파랑),g(초록),r(빨강),c(청록),y(노랑),k(검정),w(흰색) 마커:o(동그라미),v(역삼각형),^(삼각형),s(네모),+(플러스),.(점)
In [7]:
#선 옵션
plt.plot(data,'gv') #색상마커를 붙여서 표현함
Out[7]:
[<matplotlib.lines.Line2D at 0x1deef588820>]
In [8]:
plt.plot(data,'+') #기본색은 b이다
Out[8]:
[<matplotlib.lines.Line2D at 0x1deef5e4a30>]
plt.figure로 사이즈 조절
In [9]:
plt.figure(figsize=(5,5)) #inch단위로 그래프의 크기를 조정(가로,세로)
#figure아래에 있는 모든 plt.plot에 적용된다.
plt.plot(data,'k+')
plt.show()
In [11]:
## 그래프 겹치기 + legend 달기
#cumsum() 누적합 처음부터 앞으로 갈수록 기존값을 더해준다.
data = np.random.randn(30).cumsum()
Out[11]:
array([ 1.39535272, 1.84115644, 1.83005359, 0.03090168, 0.13004571, 0.3229882 , -0.59256883, 0.38523677, 0.53852537, -0.41702528, -1.76895795, -0.99475965, -2.02070379, -2.12861256, -1.93615441, -1.00805542, -1.82813983, -2.71689985, -1.09851444, -1.17230492, -2.56364059, -1.6201836 , -1.38420042, -2.00843898, -1.89225319, -2.9741577 , -2.41125962, -4.00877196, -5.15553627, -5.30058592])
In [17]:
# drawstyle = 'steps-post'를 써주면 2개의 동일한 plot을 사용할경우 합치기 가능
plt.plot(data,'k--',label='default')
plt.plot(data,'k-',drawstyle='steps-post',label='stpes-post') #k-를 하면 직각그래프됨
###### 주의 !!!!!!!!!!!!!#################
plt.legend() #위의 label만 쓰면 표시가 안되고 legend를 선언해줘야지만 표시된다 주의 할것
plt.show()
In [22]:
#label 색칠하기
font2 = {'family': 'fantasy',
'color': 'deeppink',
'weight': 'normal',
'size': 'xx-large'
}
In [23]:
## 그래프에 이름달기
plt.plot(np.random.randn(1000).cumsum())
plt.title("randmo graph") #그래프의 제목달기
plt.xlabel('Stages') # 그래프의 x축 제목달기
plt.ylabel('values',fontdict=font2) # 그래프의 y축 제목다리
plt.xticks(rotation=45) #그래프 x축 값들 회전시키기
plt.show()
In [24]:
plt.savefig('saving-graph.svg')
<Figure size 432x288 with 0 Axes>
In [ ]:
728x90
반응형
'프로그래밍 > Python' 카테고리의 다른 글
[Python].ipynb to .py (Window, Linux) / convert .ipynb to .py (0) | 2022.04.11 |
---|---|
[Jupyter notebook] 주피터 노트북 모양대로 티스토리에 글쓰기 (0) | 2021.06.23 |
[Numpy,Matplotlib] 4.이미지 시각화도 가능하다 (0) | 2021.06.18 |
[Numpy,Matplotlib] 2.Numpy는 차원을 늘리고 줄일수 있다 (0) | 2021.06.18 |
[Numpy,Matplotlib] 1. 배열다루기+시각화의 기초 (0) | 2021.06.18 |