kaggle :ScatterLine (Q11)
kaggle dictation (05)
plotly.graph_objects as go: 를 이용한 Scatter + line G
산점도
- bivariate”이변수” 값을 시각화 하는 기본적인 그래프.
- correlation: Positive, Negative, non
- 두 개의 변수 각각의 분포과 변수간의 관계를 확인 할 수 있다.
ref.
0. data set
https://www.kaggle.com/miguelfzzz/the-typical-kaggle-data-scientist-in-2021
Subject : 가장 많이 이용하는 computer platform(hardware)
1. data 읽어오기 + data Frame 만들어 주기
1 | platform = ( |
ide를 dataframe화 완료.
Q11의 column이름 까지 재설정 완료.
2.표 설정.
1 | ide = ( |
3. percent 추가
1 | platform['percent'] = ((platform['Count'] / platform['Count'].sum())*100).round(2).astype(str) + '%' |
3. 색 지정
1 | colors = ['#033351',] * 6 |
4. 표 재 설정
1 | platform = (platform |
- .sort_values(by = [‘Count’]) : [Count]로 정렬,
- .iloc[0:15] platform의 column 선택: 0~15까지 data 가져오기
- .reset_index() : data와 상관 없는 새 index 가져오기
5.plotly.graph_objects.Scatter()
본격적으로 Scatter G 만들기.
## 산점도 점 찍기
1 |
|
- x = platform[‘Count’], y = platform[“Platform”],
- x축, y축 설정
- text = platform[‘percent’],
- text를 넣는다고 하는데 안보이네
- mode = ‘markers’,
- Text, lines+markers, makers, line 이 가능 한거 같다.
- Scatter.mod
- marker_color =colors, marker_size = 12)
- 산점도 안에 있는 점의 색과 크기
## 산점도에 for문을 이용하여 line 연결하기
1 | for i in range(0, len(platform)): |
for i in range(0~platform의 길이만큼)
fig. add_shape()
type = ‘line’
- line모양의 grape shape add
x0 = 0, y0 = i,
- 초기값
x1 = platform[“Count”][i],
x축 Index
y1 = i,
y축 Index, 마지막 값
line=dict(color=colors[i], width = 4)
line의 세부 설정, 색과 두께
- flatform은 .iloc[0:15] 로 뽑아진 list 형식
따라서 platform[“Count”][i]값을 뽑아 낼 수 있다.
6. update_traces()
1 | fig.update_traces(hovertemplate='<b>Platform</b>: %{y}<br><extra></extra>'+ |
7. Design
1 | fig.update_xaxes(showgrid=True, gridwidth=1, gridcolor='#9f9f9f', ticklabelmode='period') |
8. Annotation
1 | fig.add_annotation(dict(font=dict(size=14), |
kaggle :ScatterLine (Q11)
https://yoonhwa-p.github.io/2021/11/09/kgg/Kgg_plotly_ScatterLine/
You need to set
install_url
to use ShareThis. Please set it in _config.yml
.