티스토리 뷰
bar graph
- x축이나 y축 중 하나의 값이 카테고리형일 경우 bar 형태의 그래프가 효과적임
- 세로방향 바그래프 : plt.bar(x, y, color=[색상], width=폭)
- 가로방향 바그래프 : plt.barh(x, y, color=[색상], width=폭)
- 가로 <-> 세로 바그래프 형태를 전환할 때에는 눈금 설정값, 축 라벨 등의 값을 재설정해야함
세로 바그래프
y = [80, 70, 40, 90, 60, 90]
xlabel = ['국어', '수학', '영어', '과학', '미술', '체육']
plt.bar(xlabel, y)
plt.yticks(np.linspace(0, 100, 5))
plt.ylabel('점수')
plt.show()
가로 바그래프
y = [80, 70, 40, 90, 60, 90]
xlabel = ['국어', '수학', '영어', '과학', '미술', '체육']
plt.barh(xlabel, y)
plt.xticks(np.linspace(0, 100, 5))
plt.xlabel('점수')
plt.show()
바그래프 나란히 그리기
- 바의 폭 크기 지정한 후, 수동으로 다음 그려질 그래프 위치를 지정해야함
x = np.arange(5)
women = [80, 70, 40, 90, 60]
men = [70, 80, 45, 75, 80]
child = [x-10 for x in men]
xlabel = ['국어', '수학', '영어', '과학', '미술']
bar_width = 0.3
plt.bar(x, women, width=bar_width, label='여자')
plt.bar(x + bar_width, men, width=bar_width, label='남자')
plt.bar(x + (bar_width*2), child, width=bar_width, label='미성년자')
plt.xticks(x + bar_width, xlabel)
plt.ylabel('점수')
plt.legend(loc='best')
plt.show()
바그래프 쌓아 그리기
- 바 그래프를 쌓아서 스택 형태로 그릴 수 있음
- 어떤 그래프를 아래에 둘 것인지 bottom 옵션으로 지정 필요
bar_width = 0.35
plt.bar(x, women, width=bar_width, label='여자', bottom=men)
plt.bar(x, men, width=bar_width, label='남자')
plt.xticks(x, xlabel)
plt.ylabel('점수')
plt.legend(loc='upper right')
plt.show()
'데이터 시각화' 카테고리의 다른 글
[matplotlib 그래프 튜토리얼] 07. 그래프 (hist, scatter, imshow) (0) | 2023.12.28 |
---|---|
[matplotlib 그래프 튜토리얼] 06. 그래프 (pie) (0) | 2023.12.28 |
[matplotlib 그래프 튜토리얼] 04. 그래프 (subplot, multi-line) (0) | 2023.12.28 |
[matplotlib 그래프 튜토리얼] 03. plot (figure) (0) | 2023.12.28 |
[matplotlib 그래프 튜토리얼] 02. plot (style.context, with) (1) | 2023.12.28 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 장고 태그달기
- 장고 게시판
- 알파벳 카운팅
- Django
- CellForRowAt 호출안됨
- 데이터베이스 추천
- CellForRowAt Not Called
- UITableViewController Not Working
- 웹 배포
- pythonanywhere배포
- 실시간 데이터베이스
- python 웹 배포
- 테이블출력안됨
- pythonanywhere배포방법
- Firebase 데이터베이스 추천
- iOS 데이터베이스
- django pythoneverywhere
- 까만 화면
- iOS 검은 화면
- django 태그
- cleaned_data
- django 개발일지
- django clean
- django 로그인접근
- iOS 화면 안나옴
- ModelForm Form 차이
- django tag
- django 게시판
- iOS UITableView 출력안됨
- Realtime Database
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함