Python
Matplotlib
언제나즐거운IT
2024. 5. 20. 20:21
데이터 시각화 하기위한 파이썬 라이브러리!
그중에서도 pyplot모듈을 많이 사용한다
import matplotlib.pyplot as plt
plt.title('only English')
plt.plot([1,2,3,4,5],[20,10,50,40,30]) # 그래프를 작성해서,
plt.show() # 출력!
plt.plot([32.8,38.4,36.5],color='red',label='high')
plt.plot([17.5,16.8,22.3],color='blue',label='low')
# 색뿐만아니라 선모양,마커표시 등의 설정사항을 변경하거나 추가가능
plt.legend() # 범례
plt.show()
기온 공공데이터 csv 받아와서
최고기온 [], 최저기온 [] 가공하고
그걸 그래프로 출력해주세요!
2024년 4월 데이터로 해보자~
high=[]
low=[]
with open('test.csv','r') as file :
data=csv.reader(file)
header=next(data)
print(header)
for row in data :
if row[-1] == '' :
break
high.append(float(row[4]))
low.append(float(row[-3]))
plt.title('the temperatures of April 2024')
plt.plot(high,color='hotpink',label='high')
plt.plot(low,color='lightblue',label='low')
plt.legend()
plt.show()