티스토리 뷰

step1. 맥북 한글 폰트 설정: AppleGothic이용하기

from matplotlib import font_manager, rc
rc('font', family = 'AppleGothic')

step2. csv파일 안깨지게 불러오기

  1. 먼저 엑셀 csv 파일을 저장할 때 UTF-8 CSV파일로 저장함
  2. 한글이 깨지면 engine = 'python'이용
df = pd.read_csv('경로/파일이름.csv', engine = 'python)

⇨ 데이터 프레임 출력 결과

선수명 경기수 타수 득점 안타
홍길동 137 476 84 176
일지매 131 483 91 177
전우치 106 388 84 141
강감찬 125 498 103 173

 

step3. 컬럼별로 데이터 만들기

data1 = df['경기수']
data2 = df['득점']
data3 = df['안타']
name = df['선수명']

 

step4. 라인그래프 설정

plt.style.use('ggplot')
fig = plt.figure()
ax = fig.add_subplot(111)

 

step5. 그래프 그리기

plt.style.use('ggplot')
fig = plt.figure()
ax = fig.add_subplot(111)

ax.plot(name, data1, label = '경기수')
ax.plot(name, data2, label = '득점')
ax.plot(name, data3, label = '안타')

 

step6. 축 제목과 범례 그리기

plt.style.use('ggplot')
fig = plt.figure()
ax = fig.add_subplot(111)

ax.plot(name , data1 , label = '경기수')
ax.plot(name , data2 , label = '득점')
ax.plot(name , data3 , label = '안타')

ax.set_title('선수별 기록')
ax.set_ylabel('건수(단위:건)')
ax.set_xlabel('선수명')
ax.legend(loc=1)
plt.show()
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
글 보관함