728x90
안녕하세요. 쇼미요미입니다.
나도코딩님을 통해 학습한 데이터 시각화 내용입니다.
오늘은 산점도 그래프에 대해서 알아보도록 하겠습니다.
1. 그래프 그리기
plt.scatter(df['영어'],df['수학'])
plt.xlabel('영어')
plt.ylabel('수학')
2. 원 크기 랜덤으로 변경
import numpy as np
sizes = np.random.rand(8)*1000
plt.scatter(df['영어'],df['수학'], sizes=sizes)
plt.xlabel('영어')
plt.ylabel('수학')
3. 원 색을 랜덤으로 변경
- c는 색깔 분포를 뜻함
- cmap은 컬러맵
sizes = df['학년'] * 100
#학년별로 분포를 다르게 그래프를 그림 (cmamp은 컬러맵)
plt.scatter(df['영어'],df['수학'], sizes=sizes, c=df['학년'], cmap='plasma') #구글에서 검색해서 골라서 사용하면 됨
plt.xlabel('영어')
plt.ylabel('수학')
#크기는 전체 크기의 50%, 위치는 가로로 정의하여 학년별로 컬러바를 노출함
plt.colorbar(ticks=[1,2,3], label='학년', shrink=0.5, orientation='horizontal')
Choosing Colormaps in Matplotlib — Matplotlib 3.5.0 documentation
Colormaps are often split into several categories based on their function (see, e.g., [Moreland]): First, we'll show the range of each colormap. Note that some seem to change more "quickly" than others. Sequential2 Many of the \(L^*\) values from the Seque
matplotlib.org
728x90
'Python > Matplotlib' 카테고리의 다른 글
[Matplotlib] 원 그래프 (0) | 2022.05.04 |
---|---|
[Matplotlib] 누적 막대 그래프 (0) | 2022.05.04 |
[Matplotlib] 막대 그래프 (0) | 2022.05.04 |
[Matplotlib] DataFrame 활용하여 그래프 그리기 (0) | 2022.05.04 |
[Matplotlib] 파일 저장 (0) | 2022.05.04 |
댓글