728x90
반응형

 

* 본 포스팅은 주피터 노트북에서 진행하였다.

 

!pip install matplotlib
import matplotlib.pyplot as plt
data = [1,2,3,4,3,2,1]
plt.figure('그래프 이름')
plt.plot(data)
plt.show()

 

import matplotlib.pyplot as plt
x = [10, 20, 30, 40, 50, 60, 70]
y = [1,2,3,4,5,2,1]
plt.figure('그래프 이름')
plt.plot(x,y)
plt.show()

 

 

import matplotlib.pyplot as plt
import numpy as np
time = np.arange(0,10,0.01)
y = np.sin(time)
plt.figure('그래프 이름')
plt.plot(time,y)
plt.show()

 

이 코드의 arange는 0부터 10까지 0.01간격으로 등분

 

 

import matplotlib.pyplot as plt
import numpy as np
time = np.arange(0,10,0.01)
sin_y = np.sin(time)
cos_y = np.cos(time)
plt.figure('그래프 이름')
plt.plot(time,sin_y)
plt.plot(time,cos_y)
plt.show()

 

import matplotlib.pyplot as plt
import numpy as np
time = np.arange(0,10,0.01)
sin_y = np.sin(time)
cos_y = np.cos(time)
plt.figure('sin, cos 그래프')
plt.plot(time,sin_y, label='sin')
plt.plot(time,cos_y,label='cos')
plt.legend() #범례
plt.xlabel('time')
plt.ylabel('value')
plt.title('sin, cos Grapeh') #그래프 이름
plt.grid() #그리드 설정
plt.show()

 

import matplotlib.pyplot as plt #막대 그래프
import numpy as np
data=[10,20,30,55]
x=[0,1,2,3]
plt.bar(x,data,width=0.3)
plt.show()

 

가로형 막대 랜덤 으로 생기기

 

1.

import matplotlib.pyplot as plt #막대 그래프
import numpy as np
y_data = []
x_data = []
for i in range(6):
    x_data.append(i)
    y_data.append(np.random.rand()*20)
plt.bar(x_data, y_data,width=0.5)
plt.show()

 

2.

import matplotlib.pyplot as plt #막대 그래프
import numpy as np
a = np.random.random(4)
data = np.random.random(4)
plt.bar(a,data,width=0.1)

 

가로형 막대 그리기

import matplotlib.pyplot as plt #막대 그래프
import numpy as np
data=[10,20,30,5]
x=[1,2,3,4]
plt.barh(x,data,height=0.3)
plt.show()

 

원형 그래프 그리기

import matplotlib.pyplot as plt #막대 그래프
import numpy as np
data=[10,20,30,5]
plt.pie(data)
plt.show()

728x90
반응형

+ Recent posts