일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- ML
- seaborn
- matplotlib.pyplot
- AISCHOO8기
- 구글colab
- 배열 회전시키기
- 통계그래픽
- ML기초
- read_html
- 파이썬 그래프
- AI SCHOOL
- axes-level
- 지하철적자원인
- 상관계수분석
- RandomForest
- 중복된 문자제거
- 배열의 유사도
- 미드프로젝트
- 멋사AI스쿨
- Seaborn 튜토리얼
- 머신러닝
- 시각화
- 핸즈온머신러닝
- 멋쟁이사자처럼
- 파이썬데이터타입
- fromkeys
- figure-level
- pandas로 그래프
- AISCHOOL8기
- 노인무임승차
- Today
- Total
코린이 성장일기
[TIL] matplotlib.pyplot 라이브러리 본문
오늘은 서울시에서 공개한 코로나19 발생동향을 가지고 분석 기초를 배웠다.
지난 미니 프로젝트에서 혼자 시각화해보려고 거의 복사 붙여넣기를 했었는데,,
뭐가 뭔지 몰랐다가 이제야 조금 원리를 알아가게 되었고, 좀 더 알아보고 싶었다.
시각화 라이브러리 사용의 시작
matplotlib.pyplot
왜 matplotlib.pyplot을 불러오는지 궁금했는데, matplotlib의 모듈이 꽤 많고, 거기서 우리가 시각화하기 좋은 모듈을 가져오는 것이었다.
💡 matplotlib의 모듈
- matplotlib
- matplotlib.afm
- matplotlib.animation
- matplotlib.artist
- matplotlib.axes
- matplotlib.axis
- matplotlib.backend_bases
- matplotlib.backend_managers
- matplotlib.backend_tools
- matplotlib.backends
- matplotlib.bezier
- matplotlib.blocking_input
- matplotlib.category
- matplotlib.cbook
- matplotlib.cm
- matplotlib.collections
- matplotlib.colorbar
- matplotlib.colors
- matplotlib.container
- matplotlib.contour
- matplotlib.dates
- matplotlib.docstring
- matplotlib.dviread
- matplotlib.figure
- matplotlib.font_manager
- matplotlib.fontconfig_pattern
- matplotlib.ft2font
- matplotlib.gridspec
- matplotlib.hatch
- matplotlib.image
- matplotlib.layout_engine
- matplotlib.legend
- matplotlib.legend_handler
- matplotlib.lines
- matplotlib.markers
- matplotlib.mathtext
- matplotlib.mlab
- matplotlib.offsetbox
- matplotlib.patches
- matplotlib.path
- matplotlib.patheffects
- matplotlib.pyplot
- matplotlib.projections
- matplotlib.quiver
- matplotlib.rcsetup
- matplotlib.sankey
- matplotlib.scale
- matplotlib.sphinxext.mathmpl
- matplotlib.sphinxext.plot_directive
- matplotlib.spines
- matplotlib.style
- matplotlib.table
- matplotlib.testing
- matplotlib.text
- matplotlib.texmanager
- matplotlib.textpath
- matplotlib.ticker
- matplotlib.tight_bbox
- matplotlib.tight_layout
- matplotlib.transforms
- matplotlib.tri
- matplotlib.type1font
- matplotlib.units
- matplotlib.widgets
- matplotlib._api
- matplotlib._enums
- mpl_toolkits.mplot3d
- mpl_toolkits.axes_grid1
- mpl_toolkits.axisartist
matplotlib의 모듈이 상당히 많다. . . .
그 중에 우리가 사용하는 matplotlib.pyplot 모듈은 MATLAB와 비슷하게 명령어 스타일로 동작하는 함수의 모음이라고 한다.
간편히 그래프, 선, 축을 표현하는 것에 사용된다고 한다.
❗ 그러니까 이름 그대로 파이썬에서 그래프를 그리기 위한 !!❗
🧑💻 참고해볼 만한 사이트
1. 저기 저 모듈 모음 가져온 곳이자, 한국어로 번역되어 설명되어 있다.
https://runebook.dev/ko/docs/matplotlib/-index-#pyplot
Matplotlib 3.6 한국어
runebook.dev
2. matplotlib.pyplot에 대해 설명되어 있다. 한국인이 작성하신 듯 !
01. Matplotlib 기본 사용
 Matplotlib 라이브러리를 이용해서 그래프를 그리는 일반적인 방…
wikidocs.net
본격적으로 시각화 연습을 살짝 해보았다.
koreanize-matplotlib ( 시각화를 위한 폰트 설정 )
GitHub - ychoi-kr/koreanize-matplotlib: install & import하는 것만으로 matplotlib에서 한국어를 표시할 수 있습
install & import하는 것만으로 matplotlib에서 한국어를 표시할 수 있습니다. - GitHub - ychoi-kr/koreanize-matplotlib: install & import하는 것만으로 matplotlib에서 한국어를 표시할 수 있습니다.
github.com
맷플롯립은 한글을 쓰면 깨지기 때문에 폰트를 설정해주어야 한다. 작년쯤인가 멋진 분께서 한글폰트를 위한 모듈을 만들어주셨다고 한다. 한줄이면 한글폰트 작동이 잘된다.
# 설치해주시구요
!pip install koreanize-matplotlib
import koreanize_matplotlib
# 그래프에 retina display 적용
%config InlineBackend.figure_format = 'retina'
# 그래프 그려보기
pd.Series([1,3,-5,7,9]).plot(title="한글", figsize = (12,3))
시각화에 사용하기
데이터를 전처리해서 연도월에 대한 빈도수를 넣어둔 시리즈 타입을 시각화해보았다.
대략 이런 데이터...를 시각화하는 것은 생각보다 간단했다.
# 연도월을 시각화 합니다.
year_month.plot(kind = 'bar', figsize=(12,3), title='월별 확진 수', rot=80)
요렇게 시리즈에 .plot 만 붙여주고 그 안의 설정들만 잘 해주면 예쁘게 만들 수 있다.
kind : 그래프 형태 ( 기본적으로 선그래프로 설정되어 있다 )
figsize : 캔버스 크기
title : 타이틀 제목
rot : x축 각도 변경
바로 막대그래프로 만들고 싶다면, .plot.bar() 이렇게 해주면 됌! 안에 들어가는 파라미터들은 동일하게 조정할 수 있다.
그러면, 아래와 같은 그래프가 주피터에서 그려진다.
시리즈 뿐만 아니라 데이터프레임도 시각화 가능! 한 곳에 그래프가 여러 개 그려진다.
"확진수"와 "누적확진수"가 함께 들어있는 df_all_day라는 데이터 프레임을 시각화하면 오른쪽과 같이 2개의 그래프가 그려졌다.
이 형식 외에도 우리가 그릴 수 있는 그래프는 많았음....
scatter , box 형태
또 다른 형태들 .. .
파이차트도 가능함미다..ㅎㅎ
판다스에서 값들을 시각화하기에 좋은 함수들이 많이 있었다.
🧑💻 강사님께서 알려주신 사이트
강사님께서 시각화를 위해 읽어보라고 하신 자료에서 사진을 가져와 보았다.
https://pandas.pydata.org/docs/getting_started/intro_tutorials/04_plotting.html
How do I create plots in pandas? — pandas 1.5.3 documentation
For this tutorial, air quality data about \(NO_2\) is used, made available by OpenAQ and using the py-openaq package. The air_quality_no2.csv data set provides \(NO_2\) values for the measurement stations FR04014, BETR801 and London Westminster in respecti
pandas.pydata.org
https://pandas.pydata.org/docs/user_guide/visualization.html
Chart visualization — pandas 1.5.3 documentation
Chart visualization Note The examples below assume that you’re using Jupyter. This section demonstrates visualization through charting. For information on visualization of tabular data please see the section on Table Visualization. We use the standard co
pandas.pydata.org
이것만 마스터해도 시각화를 조금 더 수월하고 예술적으로 할 수 있을 것 같다. 👍
아직 전반적인 거만 보고 디테일하게 좀 더 읽다보면 시간이 금방간다 . .. ..
Time flies like an arrow. . . . .
'멋사 AI스쿨8기' 카테고리의 다른 글
[멋사AI스쿨8기] 미드프로젝트 1 (0) | 2023.03.02 |
---|---|
[멋사AI스쿨8기] WIL - SQL(ROLLUP, WINDOW함수) (0) | 2023.02.09 |
[멋사AI스쿨8기] WIL - 다산콜센터의 주요 민원(자주 묻는 질문)에 대한 답변정보 수집 (0) | 2023.01.19 |
[멋사AI스쿨8기] WIL : 데이터 수집 기초 (0) | 2023.01.12 |
[멋사AI스쿨8기] TIL : 파이썬 문법 5일차 (1) | 2023.01.06 |