티스토리 뷰
step1. 맥북 한글 폰트 설정: AppleGothic이용하기
from matplotlib import font_manager, rc
rc('font', family = 'AppleGothic')
step2. csv파일 안깨지게 불러오기
- 먼저 엑셀 csv 파일을 저장할 때 UTF-8 CSV파일로 저장함
- 한글이 깨지면 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()
'파이썬' 카테고리의 다른 글
결측치 처리 (0) | 2023.03.26 |
---|---|
파이썬 활용하여 자동으로 이메일 보내기 (0) | 2021.06.13 |
여러가지 통계분석 (0) | 2021.06.13 |
nltk 패키지 / 영문 텍스트 분석하기 / 워드클라우드 (0) | 2021.06.13 |
(MAC OS)matplotlib을 이용한 다양한 그래프 그리기 / bokeh 그래프 그리기 (0) | 2021.06.13 |